{"id":21231109,"url":"https://github.com/izevaka/powersensor-home-assistant","last_synced_at":"2025-07-09T07:08:17.002Z","repository":{"id":39911862,"uuid":"469260298","full_name":"izevaka/powersensor-home-assistant","owner":"izevaka","description":null,"archived":false,"fork":false,"pushed_at":"2023-04-26T02:52:33.000Z","size":139,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-09T07:04:49.260Z","etag":null,"topics":["home-assistant","iot","mqtt","node-red","power-monitoring","powersensor"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/izevaka.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-13T03:31:30.000Z","updated_at":"2024-05-01T13:37:34.000Z","dependencies_parsed_at":"2024-11-20T23:41:01.839Z","dependency_job_id":"fa9cbfb7-e4a0-459c-801b-2b3aa2fa1dcf","html_url":"https://github.com/izevaka/powersensor-home-assistant","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/izevaka/powersensor-home-assistant","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izevaka%2Fpowersensor-home-assistant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izevaka%2Fpowersensor-home-assistant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izevaka%2Fpowersensor-home-assistant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izevaka%2Fpowersensor-home-assistant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izevaka","download_url":"https://codeload.github.com/izevaka/powersensor-home-assistant/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izevaka%2Fpowersensor-home-assistant/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264411144,"owners_count":23603802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["home-assistant","iot","mqtt","node-red","power-monitoring","powersensor"],"created_at":"2024-11-20T23:40:59.419Z","updated_at":"2025-07-09T07:08:16.996Z","avatar_url":"https://github.com/izevaka.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Powersensor Home Assistant integration prototype\n\nThis is a first attempt at [Powersensor](https://www.powersensor.com.au) integration with Home Assistant. Pretty rough, PRs welcome :-)\n\n## Requirements\n\n- Node-RED\n- MQTT broker (e.g. Mosquitto)\n\nOptional:\n\n- Grafana\n- InfluxDB\n- SSD set-up for Raspberry Pi\n\nNote that if you are running a Raspberry PI with and SD card, this integration will probably accelerate the demise of your SD card. Generally, it's recommended to run HA on an SSD anyway; with multiple sensors updating every second, you will be overloading the SD card.\n\n## How it works\n\nThere are two components to Powersensor:\n\n- EM sensor that sits at the switchboard (sensor)\n- Power plug that is plugged into an outlet in the house (plug)\n\nThe sensor sends power readings to the plug every second or so. The plug is connected to WIFI and it sends both the readings from the sensor and the plug to the Powersensor cloud.\n\nThis integration relies an undocumented real-time API that the Powersensor app user for real-time power figures when it's open. The API is a simple pub-sub protocol over UDP.\n\nNode-RED flow connects to each plug in your network and collects readings from them. If you have multiple plugs, one of them is paired with the sensor and that plug will report both the sensor readings and the plug readings.\n\nNode-RED flow will publish messages with voltage and power readings using the following topics:\n\n- `home/energy/sensor/MAC_ADDR/power`\n- `home/energy/sensor/MAC_ADDR/voltage`\n- `home/energy/sensor/MAC_ADDR/batteryVoltage`\n\nMinimal set-up with one sensor and one plug will produce four readings:\n\n- Plug power\n- Plug voltage\n- Sensor power\n- Sensor battery voltage\n\nThe sensor does not have voltage as it's not hard-wired into the circuit. However the sensor has its own battery voltage level.\n\n## Set-up\n\nFirst of all, you need to figure out the IP and MAC addresses for your sensors. You can get these from the Powersensor app.\n\n![sensor details](/img/sensor-details.PNG)\n\nImport the Node-RED flow and configure the IP address in the \"Connect to power plug #...\" nodes. The sample has two power plugs. If you only have one, delete the unneeded nodes or add more as needed.\n\nNote that the UDP connections and listeners are separate nodes, which is a bit strange, but it's a limitation of Node-RED. When removing extra nodes, make sure that you match the outgoing (listen) port between the sending and receiving nodes. Because of this, you may see some weirdness as you are debugging the flow. Specifically, this manifestsas \"Not connected\" error message. This happens because we are trying to open a socket to a port that's already in use. If that happens, disable the flow, deploy, then enable again and re-deploy.\n\nNext step is to create sensors that turn the MQTT messages into sensor readings. These sensors can then be displayed in dashboards. See below Sensor configuration template for an example. You will need the sensors' MAC addresses for this step. Note that the plugs have both a MAC address and an IP address, whereas the power board sensor has only a mac address.\n\nOnce the sensors are configured, you should be able to see the sensor reading in Developer Tools.\n\n![Developer tools](/img/developer-tools.PNG)\n\n## Basic sensor configuration template\n\nThis configuration block creates power and voltage sensors from MQTT. The second section under `homeassistant/customize` allows customisation of friendly names, in case you want to use those directly in lovelace dashboards.\n\n### Home Assistant 2022.6 onwards\n\nNOTE: If you are running a solar sensor as well, please refer to #6 for details on how to set up the Home Assistant sensors for the Energy dashboard.\n\n```\nmqtt:\n  sensor:\n  - name: plug_name_power\n    state_topic: home/energy/sensor/MAC_ADDR/power\n    device_class: power\n    unit_of_measurement: W\n  - name: main_powersensor_sensor\n    state_topic: home/energy/sensor/MAC_ADDR/power\n    device_class: power\n    unit_of_measurement: W\n  - name: plug_name_voltage\n    state_topic: home/energy/sensor/MAC_ADDR/voltage\n    device_class: voltage\n    unit_of_measurement: V\n  - name: main_powersensor_battery_voltage\n    state_topic: home/energy/sensor/MAC_ADDR/batteryVoltage\n    device_class: voltage\n    unit_of_measurement: V\nhomeassistant:\n  customize:\n    sensor.plug_name_power:\n      state_class: measurement\n      friendly_name: Friendly Plug Name\n    sensor.main_powersensor_sensor:\n      state_class: measurement\n      friendly_name: Total Household Power\n\n```\n\n## Energy sensors (suitable for Energy dashboard)\n\nPowersensor plugs emit power readings only. To convert those into energy, you basically need to multiply power by time, also known as integrating with respect to time. Luckily HA provides built-in tooling to do exactly that using **integration** sensor. Inspiration - [Mark Wunderling's blog post](https://mwunderling.com/blog/energymonitoringha.html).\n\nThis section shows how to create energy sensors that are suitable for using in HA Energy dashboard. I found that the energy dashboard needs `state_class` to be set to `total_increasing`, even though the documentation [suggests](https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics) that `total` should work, so this particular customisation is mandatory.\n\n```\nsensor:\n  - platform: integration\n    source: sensor.main_powersensor_sensor\n    unit_prefix: k\n    round: 2\n    name: main_powersensor_sensor_energy\nhomeassistant:\n  customize:\n    sensor.main_powersensor_sensor_energy:\n      state_class: total_increasing\n      friendly_name: Total Household Energy\n```\n\n## Util\n\nThe optional `capture-sensor` utility allows direct connection to the sensor for debugging and troubleshoting purposes. This is a node.js program with a straight forward interface.\n\n```\nᐅ node capture-sensor.mjs\nHost argument required\nUsage: node capture.sensor.mjs [--raw] host [port|49476]\n```\n\nBy default, the utility outputs MQTT messages that the Node-RED flow outputs. Specifying `--raw` will switch to outputing raw JSON as it comes out from the plug. In raw mode, the protocol messages are supressed.\n\n## Limitations\n\nThe Node-RED flow is pretty fragile, I don't really trust it, but it seems to perform OK so far, including surviving HA restarts.\n\nIf you reposition the sensor and press the sensor button to show the signal strength, the sensor power reading switches into a different mode, where the reported unit is `U`. What it is is a mystery to me. I suspect it's the raw EM reading from the sensor. I fudged the multipler (approximately 20) to convert it back to watts by inspecting the output. This may be completely different in your set up. The sensor will stay in this mode for about 2 hours.\n\n## Recommended recorder configuration\n\n**UPDATE (Jul 2022):** After having run this configuration for approximately 6 months, I had to reconfigure both the recorder and InfluxDB in order to keep the database sizes in check. InfluxDB/Grafana is somewhat of a black art in itself, so I am not covering it here.\n\nThe powersensor sensors are very chatty, emtting a reading every second. This absolutely hammers the recorder database. If you have InfluxDB configured, you can get rid of state recording in the database altogether. This will reduce the DB size from something like 3GB uncompressed to 350MB, speeding up backups dramatically.\n\nBelow configuration is a subset of my set-up. I set up exclusions for any sensors that have `power` or `voltage` in the name. This will prevent these sensors from being able to be used in Lovelace state history widgets. Additionally, I set the commit interval to 30 seconds to be kind to the disk.\n\n```\nrecorder:\n  purge_keep_days: 30\n  commit_interval: 30\n  exclude:\n    domains:\n      - sun\n    entities:\n      - sensor.memory_free\n      - sensor.processor_use_percent\n    entity_globs:\n      - sensor.*voltage\n      - sensor.*power*\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizevaka%2Fpowersensor-home-assistant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizevaka%2Fpowersensor-home-assistant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizevaka%2Fpowersensor-home-assistant/lists"}