alexspires
(Alexsandro Pires)
September 22, 2020, 12:55pm
1
Hello everybody!
I have a power meter that has MQTT and my Mosquitto are receiving messages from this power meter on the same topic(so each line below is a message that comes on the same topic), how do I extract each value of these messages to a corresponding sensor via templates?
{“variable”:“EP”, “value”:3283.88,“unit”:“Wh”}
{“variable”:“I”, “value”:3.81,“unit”:“A”}
{“variable”:“PF”, “value”:0.94,“unit”:“1”}
{“variable”:“U”, “value”:220.00,“unit”:“V”}
{“variable”:“P”, “value”:787.90,“unit”:“W”}
123
(Taras)
September 22, 2020, 2:42pm
2
I helped someone else with a similar question:
I think the trick is to make the value_template more sophisticated. It should check if the value it is extracting is defined. If it’s defined, report it. If it’s not defined, report the current value (which should fill in the gaps you’re now experiencing).
Apologies but I don’t have time to fully test this but it should give you an idea on how to approach the problem.
- platform: mqtt
name: "Dew Point"
state_topic: "weewx/loop"
value_template: >-
{% if value_json.dewpoint_F…
We can adapt it to meet your requirements. For example, here’s an MQTT Sensor for “EP”:
- platform: mqtt
name: EP Sensor
state_topic: tele/energy/RESULT
value_template: >-
{% if value_json.variable == 'EP' %}
{{ value_json.value }}
{% else %}
{{ states('sensor.ep_sensor') }}
{% endif %}
expire_after: 120
device_class: energy
unit_of_measurement: Wh
2 Likes
alexspires
(Alexsandro Pires)
September 22, 2020, 8:47pm
3
Wow, that worked really nice.
Only removed device_class as I got an error with Yaml.
Anyway you really solved it!!!
Now got the values and start making the interface…appears ugly, but will improve later.
1 Like