Getting CC128 Home energy monitor data into HASS

Hi, sorry to drag this back up! I’ve been trying for a couple of days to get this to work. If I try the mqtt version from the page linked above I get stuck because I don’t know the SU password so the homeassistant user cannot run the python as root.

So I’ve had a go at the version above. However I’m not sure how to set up my configuration.yaml file for this version. I assumed (haha) that it was going to be something like adding
shell_command:
getcurrentcost: python3 /home/homeassistant/.homeassistant/CurrentCost.py

But then I’m stuck on how to add the sensors (I’ve still got the mqtt platform stuff in there).

Any help greatly appreciated!

Thanks

I have a similar CurrentCost unit that transmits on 433MHz, does yours? If so, it’s very simple to get the information into HA. I use an SDR dongle and a package called RTL_433 that can decode the CurrentCost data stream and output it in a JSON format.
I can give you more info if you are interested.

as far as I know you will need to run the python script as root / su, regardless of whether you use the API or MQTT.
What are you running HA on? Is it hass.io? If so there is no password for the default user name (root)
so (I think) you could simply call the script with sudo:

shell_command:
getcurrentcost: sudo python3 /home/homeassistant/.homeassistant/CurrentCost.py

I’m interested :slight_smile:

No, mine only transmits over the RJ45. It’s quite an old model - the original Envi. I think the key part will be to get the “platform” part of the config file correct. If I run the script in verbose mode I can see the XML coming in happily. I’m a relative HA noob. Thanks for the offer though.

Hi, thanks. No, I’m using Hassbian. Could you give me an idea of what to try in the configuration.yaml file for the sensors?

Thanks

That’s why I run the script with my normal user as SU, then all comms go via MQTT (advantage is messages are retained so when HA restarts states are still valid)
What happens if you use the MQTT version and try to run it manually?

How would I test if it was working? I can give it a go. So do you mean running it as the pi user with sudo? Note - I am not even remotely up to speed with mqtt :slight_smile:

yes that’s what I mean. if you use MQTT, you can use a tool like mqtt.fx to monitor MQTT traffic.

Sigh… I’m getting “No module named paho” when ? I run sudo python3 CurrentCost.py

If I run it without sudo it seems to run, but I don’t really know how to see if it is working using MQTT.fx. I’ve installed that and typed in my broker details but it never connects.

pip3 install paho-mqtt will install the required libraries…
if you can’t connect to your broker with MQTT.fx you might struggle sending message to it via the python script…

Thanks - seems happy as user pi, but not as soon as a I plonk sudo in front of it. The mqtt.fx thing is almost certainly user error. I’ve not used mqtt before today! In theory HA starts up an MQTT broker on web port 8080 doesn’t it?

nope, embedded MQTT port is 1883:


that’s probably why you can’t connect via MQTT.fx
try and get it to work first then you’ll know if the issue is MQTT or HA “IF” you can’t see the data in HA…

Yeah that page was where I got confused over the port numbers. Anyway, I’ve managed to get MQTT.fx to connect to the broker (yay!) so I’ll spend a bit of time understanding MQTT before I try to resolve this issue with HA and the Current Cost. As of now, it’s bedtime and I don’t know what “subscribing” in MQTT means, I’m not seeing anything flying through MQTT.fx and if I go to my server’s port 8080 in a web browser I get “Invalid Connection header: keep-alive” which at least means something is running somewhere!!!

Thanks for your help.

1 Like

OK @lolouk44, I walked myself into that! My setup runs under Ubuntu 18.04 server, although earlier versions should work as well, so I am assuming that you are familiar with Linux command line. It should be possible to run it under Windows, but I haven’t tried it. I use a USB Software Defined Radio (SDR) dongle to receive the 433MHz transmissions - nooelec.com NESDR Mini 2, about €25.

The software is RTL_433 which you need to download and compile on your linux box. I found that by folowing the instructions, I could run the software from the command line and it immediately started reporting readings from the meter.

In order to get it to run automatically, I use this service definition file:

[Unit]
Description=RTL_433 to MQTT Publisher for Watchman (R 43) and Current Cost CC128 (R 44)
After=network.target

[Service]
ExecStart=/bin/bash -c “/usr/local/bin/rtl_433 -q -R 43 -R 44 -F json | /snap/bin/mosquitto_pub -h localhost -i RTL_433 -l -t RTL_433/JSON”
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Save this as rtl_433.service in /etc/systemd/system and then run:
sudo systemctl enable rtl_433.service
sudo systemctl start rtl_433.service

What this does is takes the output of RTL_433 and pipes it to mosquitto for publishing as a topic. Change the localhost on ExecStart if your MQTT server is on a different box.

You can then create a sensor on Home Assistant to report the readings:
# RTL_433 Sensors

  • platform: mqtt
    state_topic: “RTL_433/JSON”
    name: “Power Consumption”
    unit_of_measurement: “kWh”
    value_template: “{{ value_json[‘power0’] }}”

Pat

Thanks for the details, much appreciated.
quick questions:

  1. are you using more than 1 energy monitor? if so how do you select the channel (Sorry if this is trivial, I’ve not looked into any of your links yet)
    2 which CurrentCost do you have? Mine’s an EnviR and I’m not sure it’s got built in 433MHz
    Thanks again

Hi @lolouk44, I am only using one monitor on the mains cable coming into my house. Here is the MQTT output from it:

"2018-08-03 10:41:06", "model" : "CurrentCost TX", "dev_id" : 77, "power0" : 1094, "power1" : 0, "power2" : 0}

As you can see, I am using power0, and there is nothing on power1 or power2, so you can easily adapt my solution to read all three.

Mine is rebadged by my electricity supplier, but the model number CC128 is embossed on the back of the display. If you can find the model number, a quick google will tell you it’s capabilities. Just look for anything that mentions 433MHz.

Thanks I have an RFXCOM RFXTRX433 which does not (yet?) support this. I have an 433MHz receiver somewhere so might try and toy with it :slight_smile:Thanks again

Finally got it working after some serious learning of Python things I’ve never used! I couldn’t get the decoding to UTF-8 working inside untangle.py, so what I did was:
read the first serial line, and discard it (otherwise I get an error)
in the loop read the xmldata and decode it before passing it to untangle.

et voila! I now have two new sensors on my homepage (I’m not using the MQTT version yet).

Thanks for your help!

Rob

1 Like

For those interested, I have just created a custom component for CurrentCost: