Hi,
I have a config that reads te mqtt value and using a json attribute template. After reboot the values (attriibutes) are lost. ANy idea how to solve this? I can only think that homeassistant gets the value and republished in different topic with retain flag, but maybe there is anoter way?
- platform: mqtt
name: "Thermostaat Slaapkamer"
availability_topic: "tele/z2t/LWT"
payload_available: "Online"
payload_not_available: "Offline"
retain: true
qos: 1
modes:
- "auto"
- "heat"
temp_step: 0.5
initial: 22
min_temp: 12
max_temp: 23
json_attributes_topic: "tele/z2t/2B2C/SENSOR"
json_attributes_template: >
{% set properites = ["LocalTemperature", "TuyaTempTarget", "TuyaValvePosition", "LinkQuality", "TuyaAwayDays", "TuyaAutoLock", "TuyaAwayTemp", "TuyaScheduleHolidays", "TuyaScheduleWorkdays", "TuyaWeekSelect", "TuyaEcoTemp", "TuyaComfortTemp", "TuyaForceMode", "TuyaBoostTime", "TuyaChildLock", "TuyaPreset", "TuyaMinTemp", "TuyaMinTemp", "Manufacturer", "ModelId", "EF00<11", "EF00<24", "EF00/022C", "EF00/050D"] %}
{%- set json_template -%}
{
{%- for key in properites -%}
"{{key}}": "{{ value_json.ZbReceived['0x2B2C'][key] | default(state_attr('climate.thermostaat_slaapkamer',key)) }}"{% if not loop.last %},{% endif %}
{%- endfor -%}
}
{%- endset -%}
{{ json_template }}
action_topic : "tele/z2t/2B2C/SENSOR"
action_template: >
{% if value_json.ZbReceived['0x2B2C'].TuyaValvePosition is defined %}
{% if float(value_json.ZbReceived['0x2B2C'].TuyaValvePosition) > 0 %}
heating
{% else %}
idle
{% endif %}
{% else %}
{% if state_attr('climate.thermostaat_slaapkamer','hvac_action') == None %}
idle
{% else %}
{{ state_attr('climate.thermostaat_slaapkamer]','hvac_action') }}
{% endif %}
{% endif %}
mode_command_topic: "routing/thermostat/2B2C/mode"
mode_state_topic : "tele/z2t/2B2C/SENSOR"
mode_state_template: >
{% if value_json.ZbReceived['0x2B2C'].TuyaPreset is defined %}
{% if float(value_json.ZbReceived['0x2B2C'].TuyaPreset) == 2 %}
heat
{% elif float(value_json.ZbReceived['0x2B2C'].TuyaPreset) == 6 %}
auto
{% else %}
off
{% endif %}
{% else %}
{% if state_attr('climate.thermostaat_slaapkamer','TuyaPreset') == None %}
off
{% else %}
{{ states('sensor.thermostaat_slaapkamer') }}
{% endif %}
{% endif %}
current_temperature_topic: "tele/z2t/2B2C/SENSOR"
current_temperature_template: >
{% if value_json.ZbReceived['0x2B2C'].LocalTemperature is defined %}
{{ value_json.ZbReceived['0x2B2C'].LocalTemperature }}
{% else %}
{{ state_attr('climate.thermostaat_slaapkamer','LocalTemperature') }}
{% endif %}
temperature_command_topic: "routing/thermostat/2B2C/currentsetpoint"
temperature_state_topic: "tele/z2t/2B2C/SENSOR"
temperature_state_template: >
{% if value_json.ZbReceived['0x2B2C'].TuyaTempTarget is defined %}
{{ value_json.ZbReceived['0x2B2C'].TuyaTempTarget }}
{% else %}
{{ state_attr('climate.thermostaat_slaapkamer','TuyaTempTarget') }}
{% endif %}