Getting CC128 Home energy monitor data into HASS

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: