Hi guru’s!
A newbie here; using HA for a few weeks, in Docker.
I am still trying to get myself comfortable with HA, browsing&playing around, but still unable to get some basic thing to work.
There are some topics with similar things in subject, but those seem to be about a different problem.
I have multiple Tasmota-based devices that are running tasmota rules to perform specific tasks, like thermostat in this case.
Tasmota devices themselves were successfully discovered by HA automatically, but I want to get the information that is published when rules execute.
Normally, Tasmota’s STATE topics are used to obtain this info, but I had to suppress them to once-per-minute to save the bandwidth.
So, when rules execute, they publish many multiple things under RESULT topic:
$ grep pow1 /var/log/mosquitto/traffic.log | grep RESULT
stat/tasmo/tasmopow1/RESULT {"Var2":"-8"}
stat/tasmo/tasmopow1/RESULT {"Add2":"-7.000"}
stat/tasmo/tasmopow1/RESULT {"Mem1":"16"}
stat/tasmo/tasmopow1/RESULT {"Var1":"4.1"}
stat/tasmo/tasmopow1/RESULT {"Mem1":"16"}
stat/tasmo/tasmopow1/RESULT {"Event":"Done"}
stat/tasmo/tasmopow1/RESULT {"POWER1":"1"}
stat/tasmo/tasmopow1/RESULT {"POWER1":"0"}
stat/tasmo/tasmopow1/RESULT {"Var2":"16"}
stat/tasmo/tasmopow1/RESULT {"Add2":"17.000"}
stat/tasmo/tasmopow1/RESULT {"Var1":"4.2"}
stat/tasmo/tasmopow1/RESULT {"Mem1":"16"}
stat/tasmo/tasmopow1/RESULT {"Event":"Done"}
stat/tasmo/tasmopow1/RESULT {"POWER1":"1"}
stat/tasmo/tasmopow1/RESULT {"Var2":"16"}
stat/tasmo/tasmopow1/RESULT {"Add2":"17.000"}
stat/tasmo/tasmopow1/RESULT {"Var1":"4.1"}
stat/tasmo/tasmopow1/RESULT {"Mem1":"16"}
stat/tasmo/tasmopow1/RESULT {"Event":"Done"}
stat/tasmo/tasmopow1/RESULT {"POWER1":"1"}
stat/tasmo/tasmopow1/RESULT {"Var2":"16"}
stat/tasmo/tasmopow1/RESULT {"Add2":"17.000"}
stat/tasmo/tasmopow1/RESULT {"Var1":"4.2"}
stat/tasmo/tasmopow1/RESULT {"Mem1":"16"}
stat/tasmo/tasmopow1/RESULT {"Event":"Done"}
stat/tasmo/tasmopow1/RESULT {"POWER1":"1"}
I want to capture specific things:
stat/tasmo/tasmopow1/RESULT {"Mem1":"16"}
stat/tasmo/tasmopow1/RESULT {"POWER1":"1"}
mqtt:
- sensor:
- name: test tasmopow1 power1
unique_id: tasmopow1_power1
state_topic: stat/tasmo/tasmopow1/RESULT
# value_template: "{{ value_json['POWER1'] }}"
value_template: "{{ value_json.POWER1 }}"
- sensor:
- name: test tasmopow1 mem1
unique_id: tasmopow1_mem1
state_topic: stat/tasmo/tasmopow1/RESULT
# value_template: "{{ value_json['POWER1'] }}"
value_template: "{{ value_json.Mem1 }}"
Normal mqtt sensors do capture them, but since multiple kinds of variables are reported under the same topic, captured state is lost when next RESULT contains different data in it, and a warning is logged.
2024-02-16 16:00:32.204 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'POWER1' when rendering '{{ value_json.POWER1 }}'
2024-02-16 16:00:32.205 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'Mem1' when rendering '{{ value_json.Mem1 }}'
I think I noticed once a recommendation how to deal with this, using template trigger and sensor, but I can not find that anymore found it: Hold/retain sensor value between mqtt messages -- SOLVED! THX.
I tried that approach, but did not see any change to behaviour, probably failed to adapt it to my situation:
template:
- trigger:
- platform: mqtt
topic: stat/tasmo/tasmopow1/RESULT
payload: "True"
value_template: "{{ value_json.Mem1 }}"
sensor:
- unique_id: test_tmpl_mem1
name: "test tmpl Mem1"
state: >-
{{ trigger.payload_json.Mem1 }}
It’s not quite clear how was this supposed to work, or how was i supposed to see it’s results.
Is there a document somewhere, that would describe things like value_json, trigger.payload_json? What other options are there? I see value_json is giving me dictionary’s value, is there a way to obtain it’s key? How can I check if a dictionary contains particular key, without causing a warning?
Obviously I do not have enough understanding of basic concepts; I would be happy if somebody helped me out, directing me to docs/examples/whatever on this.
KPL