[Custom component] energenie MiHome ENER314-RT HA integration via MQTT

Now at the third version (v0.3.0) I thought I would share my custom integration mqtt-energenie-ener314rt. The integration allows local control & monitoring of the energenie range of sockets, switches, relays, radiator values and sensors using their 433Mhz radio transmitter board the ENER314-RT; there is no need for a separate MiHome Gateway.

The code, which is lightweight, executes under node.js on a raspberry pi where the ENER314-RT is installed. It communicates with Home Assistant via MQTT, and it has MQTT discovery support is built-in.

Several of us have been successfully running the code since January.

The code is still in beta, so all feedback welcome.

2 Likes

Thanks. Iā€™m relatively new to HA and have it running in my Pi 4B 8G as an HA installed image on the SD card using the Pi installer. Iā€™m using HA to learn about modern development and still trying to get my head around how it all works and all the advantages of each flavour of install.
Is the above configuration compatible with this installation or should I be running Pi OS and HA on Docker or some other way instead?
Many years ago I was a developer using embedded software and C development on OS/9 68k and Unix but didnā€™t make the leap into OO programming so itā€™s a bit of a learning curve currently as I work out the high level stuff and understand how it (magically) works at medium and low level. Thanks for any input.

Sorry for the late reply. The key thing is being able to access GPIO from the program so it needs an environment where that is enabled. I donā€™t think a shell within docker HA will work as this access is blocked by default. Try it and see!

FYI: My installation uses an old Pi2B with the ENER314-RT, this runs the MQTT broker and my software. I have HA running on a separate machine (an NPC) running HAOS.

v0.4.0 Has now been released, this includes a couple of fixes for MQTT discovery, including aligning the entity names to updated HA guidelines.

See https://github.com/Achronite/mqtt-energenie-ener314rt/blob/761547a82beee3984048e671f58f10e1088740ea/CHANGELOG.md for details.

v0.5.0 Released - Changelog below

Added

  • Configurable levels of logging within the application #24.

Fixed

  • Simplified algorithm for battery % calculation. Tries to close #31

  • Fixed a bug where the target switch state sometimes fails to be updated in MQTT for OOK devices due to a bug in dependency energenie-ener314rt#32

  • Fixed a bug where a stack trace was sometimes output for MQTT connection when exiting application

hello,
i am.new to HA and have i installed HA OS .
i installed your integration but nothing detected. can younplease let me.know what i need to install, dependencies, of your integration please

Hi @ninjaef, welcome to the community.

Unfortunately you cannot run this (AFAIK) on the same machine under a HA OS installation as it needs access to a node.js runtime environment such as Raspberry Pi OS.

I use 2 machines for my installation an NPC running HAOS and an old Pi 2 that runs debian and has the module adaptor and my code. It uses MQTT to communicate.

Hi @Achronite , thank you for helping.

So I run a Pi4 with plenty of RAM and CPU left running HAOS. So, what is there to stop me, on the same pi, installing ssh+terminal addons, logging in as root via ssh, installing node.js docker, and create a docker for your module adapter. MQTT would already be running under the HAOS?

I might even built the image from all three but small steps first.

TIA mate.

I wasnā€™t sure of your technical ā€˜levelā€™ when I responded. Yeah you would need to run a docker container that has nodejs environment and, critically, gpio (ideally spidev) access to make it work.

npm install should install the dependencies once you have a nodejs container. My module only has 3 dependencies (energenie-ener314rt, mqtt and npmlog) , but I know MQTT and npmlog have many more.

I have not heard of anyone doing this, so I would be very interested in your results!

Hi,

Thank you for this, Iā€™ve had the hat in a drawer for years and this has finally given me the push to actually use it.
Just for info Iā€™m using docker to run home assistant and mqtt.
Iā€™ve had two problems hoping you can shed some light on them, firstly,

sudo ln -s /home/pi/mqtt-energenie-ener314rt/mqtt-energenie-ener314rt.service /lib/systemd/system/
sudo systemctl daemon-reload
sudo systemctl start mqtt-energenie-ener314rt
sudo systemctl enable mqtt-energenie-ener314rt

results in this error,

ln: failed to create symbolic link '/lib/systemd/system/mqtt-energenie-ener314rt.service': File exists
Failed to start mqtt-energenie-ener314rt.service: Unit mqtt-energenie-ener314rt.service not found.
Failed to enable unit: Unit file mqtt-energenie-ener314rt.service does not exist.

Iā€™m pretty sure I followed your readme exactly, and I tried changing .../pi/... to being the user and the hostname I use just in case. If you can shed any light that would be amazing.

The second is the use of OOK devices, I am using light switches and have found while the turn off always seems to work, they donā€™t always turn on - is this something you have seen?

Thanks again for this amazing integration.

@morphok The first part is all about creating an automated startup of the application. These instructions were added by someone else to my README; ultimately you just need something to execute node app.js in the correct directory; If you are using docker you could get it to execute the node app.js command, something like this: Start node app at container start with Docker - Stack Overflow

For the second part the command to switch off/on an OOK switch is almost identical bitwise. If it isnā€™t always receiving, it will be poor signal either due to a) range or b) interference from other 433MHz radio devices in your home. You could try increasing the number of ook_xmits in your config.json file; try 20 instead of 10; this should help with interference.

To fix a) there is an aerial mod you can do on the boardā€¦ I canā€™t locate the instructions at the mo, let me know if you need it.

EDIT: Iā€™ve found the link to the aerial mod: Antenna rx gain too low - how to adjust 'pout'? Ā· Issue #100 Ā· whaleygeek/pyenergenie Ā· GitHub

v0.6.0 Released - changelog below:

Added

Extra keys ā€˜433MHzā€™ and ā€˜MiHomeā€™ added to ā€˜package.jsonā€™ (@genestealer)

Instructions added to README for joining undiscovered Monitor devices #52

Fixed

Type error on Maintenance LOW_POWER_MODE causing crash #49

Changed

MQTT Discovery: Entity names are now in Title Case (instead of all lower case)

MQTT Discovery: eTRV Climate now operates differently to align closer to the Climate modes in Home Assistant #47 (note: the numbers in brackets show the equivalent eTRV ā€˜VALVE_STATEā€™)

  • ā€˜autoā€™ (2) mode in HA means it is run by an external schedule, so has therefore been removed as not applicable
  • ā€˜heatā€™ (was 0 now 2) mode operates to the set-point temperature
  • ā€˜offā€™ (1) mode unchanged
  • ā€˜always onā€™ (0) has been removed, as there isnā€™t an equivalent in HA

MQTT Discovery: Origin added to device discovery message (@genestealer)

MQTT Discovery: Device Class for Smart Plug switch set to outlet (@genestealer)

MQTT Discovery: eTRV REPORTING_INTERVAL and Maintenance Entity categories set to config (@genestealer)

MQTT Discovery: eTRV temperature step added and set to 0.5 (@genestealer)

MQTT Discovery: Battery % now shows as dynamic icon in Home Assistant for eTRV (@genestealer) and Home Energy Monitor (@Achronite)

MQTT Discovery: ā€˜FREQUENCYā€™ and ā€˜VOLTAGEā€™ added as HA ā€˜disabled entitiesā€™ for Monitor Plug, and Smart Plug+

For those that do not watch the github repo, v0.7.2 was released last week.

The v0.7.x releases require the following updates that will need to be manually installed if upgrading from v0.6.x or below:

  • gpiod & libgpiod: New dependencies that need to be installed (e.g raspbian: sudo apt-get gpiod libgpiod-dev)

  • node.js: v18.2.0 or greater

Changes since v0.6.0 are as follows:

Added

  • Support added for MiHome Thermostat (MIHO069), including auto-messaging to obtain telemetry

  • Support added for MiHome Click (MIHO089) #79

  • MQTT Discovery: Added thermostat, including Climate Control entity

  • MQTT Discovery: Added MiHome Click

  • The number of retries is now configurable for cached commands (applies to eTRV and thermostat) by setting cached_retries in config,json (default remains at 10)

  • MQTT Discovery: Added ā€˜Battery Timestampā€™ (mapped to MQTT VOLTAGE_TS), ā€˜Diagnostics Ranā€™ (mapped to DIAGNOSTICS_TS) and 'Valve Exercised (mapped to VALVE_TS) for eTRV

  • MQTT Discovery: Added ā€˜Identifyā€™ Button for eTRV

  • Setting target temperature now caters for 0.5 increments (previously integer)

  • A different mechanism of reporting processed commands has been implemented for the thermostat, that relies on the fact that when (and only when) the thermostat processes a command it outputs itā€™s telemetry data. This mechanism has been used to assume that the command just sent to the device (upon WAKEUP) has been processed successfully; This command has itā€™s retained state set in MQTT [#61](Thermostat retained topics Ā· Issue #61 Ā· Achronite/mqtt-energenie-ener314rt Ā· GitHub

  • MQTT Discovery: A new device mqtt-energenie-ener314rt has been added to represent the software and the ENER314-RT board, which includes a ā€˜Discoverā€™ button, ā€˜Connected Stateā€™ and reports the number of discovered monitor (FSK) devices. All Discovered ā€˜monitorā€™ devices are automatically linked to this new device as ā€˜Connected devicesā€™. The README examples have also been updated to show how to link these to the board device using via_device.

  • Home Assistant: Added ā€˜Discoverā€™ button for the board device; this will perform a 10 second auto-scan and will update the device list via MQTT Discovery for all devices found.

  • #81 Auto-retry switch command added for MIHO005, enabled by default, disabled by adding retry: false into config.json. This functions checks that the resulting monitor message matches the (just) sent command; if it is different it retries the command (indefinitely)

  • #80 ā€˜Versionā€™ added to entity mqtt-energenie-ener314rt, which shows if a software update is available for this applicationt. This checks runs once on startup and then at 3:26AM every day.

Fixed

  • Added options to mqtt service for increased resilience of restarting the service upon failure #62(@genestealer)

  • Removed verbose logging of MQTT password #66

  • Only enable discovery if monitoring is also enabled #82

Changed

  • BREAKING DEPENDENCIES: The version of mqtt.js has been updated, this newer version required node.js >= v18.2.0

  • BREAKING DEPENDENCIES: The version of energenie-ener314rt needed is v0.7.x. This uses a newer GPIO library that is compatible with the pi5. gpiod and libgpiod will need to be installed first

  • Pretty printed all device JSON files

  • MQTT Discovery: OEM Part Number and Device ID added to HA device model field (@genestealer)

  • Submitting a cached command will now replace the existing cached command for the device

  • Added data value to the reporting of command when it has been successfully cached (also only update MQTT when this is set to 0=None) #69,

e.g. ā€œSet Temperatureā€ becomes ā€œSet Temperature 18.5ā€

  • Bumped MQTT to 5.3.5 #62

  • MQTT Discovery: In line with HA best practices, the primary entities for each of the FSK control devices (see table below) have had their names updated to ā€˜Noneā€™/null, e.g: sensor.motion_sensor.XXX.motion ā†’ sensor.motion_sensor.XXX. These entities are indicated by "main":true in the device json files.

Device Description Primary Entity name set to null
MIHO005 MiHome Smart Plug+ (Purple) switch
MIHO013 MiHome Radiator Valve climate control
MIHO069 MiHome Heating Thermostat climate control

See also: Release v0.7.2 Ā· Achronite/energenie-ener314rt Ā· GitHub - Notably pi5 support and GPIO driver changes