So, I have an initial proof of concept to get the data to HA in JSON format:
nc currentcost.lan 23 | while read line; do
printf "%s\n" $line | ./xml2json | mosquitto_pub -t 'tele/currentcost/SENSOR' -s
done
(The above should be easily translated for those using the serial port adapter to read from the serial port at 57600 baud instead of connecting to a telnet port. e.g. stty -F 57600 /dev/ttyUSB0
and cat /dev/ttyUSB0 | while read ...
)
xml2json
is a header-only implementation of an XML to JSON converter, which should be fairly straightforward to compile for the ESP, so I’ll probably make a custom Tasmota build to solve this long term.
And I can see the data arriving in HA, looking like:
{
"msg": {
"src": "CC128-v1.29",
"dsb": "01915",
"time": "22:59:09",
"tmpr": "21.9",
"sensor": "0",
"id": "02639",
"type": "1",
"ch1": {
"watts": "00047"
},
"ch2": {
"watts": "00231"
},
"ch3": {
"watts": "00466"
}
}
}
I am using the following sensor to extract the different channel values as attributes, as well as a combined ch1+ch2+ch3 value as the sensor “state”.
- platform: mqtt
name: "Electricity Use"
state_topic: "tele/currentcost/SENSOR"
value_template: " {{ value_json.msg.ch1.watts | int + value_json.msg.ch2.watts | int + value_json.msg.ch3.watts | int }} "
unit_of_measurement: "Watt"
json_attributes_topic: "tele/currentcost/SENSOR"
json_attributes_template: " {{ {'temp': value_json.msg.tmpr | float, 'ch1':value_json.msg.ch1.watts | int, 'ch2':value_json.msg.ch2.watts | int, 'ch3':value_json.msg.ch3.watts | int } | tojson}} "
And I also got the integration:
plugin configured, based on the combined sum, which is where my next question comes in. For some reason, even though I have the prefix configured to k
, there is no division of the resulting value, meaning that my resulting consumption in kWh is off by a factor of 1000. Any suggestions on how I can fix the calculation of the integral? And any suggestion how I can graph the individual phases, or should I simply make a template sensor that references the individual attributes?
- platform: integration
source: sensor.electricity_use
name: "Energy Consumed"
unit_prefix: k
round: 2
See attached image.