yulbob
1
Hi All
I have set up a sensor in MQTT to get energy usage from some zigbee plugs
They report their value as “0x00000000010E” (for example)
What’s the best way to convert this to a value Home Assistant can use?
I’ve tried
value|int(base=16)
and
value|replace('0x','')|int(base=16)
But I just keep getting “unavailable” when looking at the entity
francisp
(Francis)
2
Could be for a number of reasons. It would help if you show us the whole mqtt message and your sensor definition ?
yulbob
3
Sure,
MQTT message
23:18:55.995 MQT: tele/tasmota_2D5804/CCA9/SENSOR =
{
"ZbReceived": {
"0xCCA9": {
"Device": "0xCCA9",
"Name": "Plug1",
"CurrentSummationDelivered": "0x000000000110",
"Endpoint": 1,
"LinkQuality": 134
}
}
}
Yaml
mqtt:
sensor:
- name: "Plug1 Total Energy"
availability_topic: "tele/tasmota_2D5804/LWT"
unique_id: "0xCCA9"
state_topic: "tele/tasmota_2D5804/CCA9/SENSOR"
value_template: >
{% if value_json['ZbReceived']['0xCCA9']['CurrentSummationDelivered']|int(base=16) > 0 %}
{{ value_json['ZbReceived']['0xCCA9']['CurrentSummationDelivered']|int(base=16) }}
{% else %}
{{ states(entity_id) }}
{% endif %}
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
icon: "mdi:flash"
Ultimate goal here is to grab the summationdelivered number and use it on the energy dashboard