Hi,
I made some investigations and changes, and I think I got it working a even little bit better now…
If the checkbox “Send changes in separate MQTT messages” is checked, the “<yourd_id>/thermostate/properties” is not the “full” json where you are extracting the data from, but all the values are being send only in the separate mqtt topics. Thats on what I built my previous code, and also the automations which doing the “hammering in the values few times”. Aditionally, your code does not have the “action_topic” which determines the current action of the thermostate.
Currently this mqtt config is working for my thermostate with the Firmware Version 1.25b
mqtt:
climate:
- name: Thermostat
unique_id: termostat
device:
configuration_url: http://<ip of your thermostate>/config
manufacturer: Tuya
model: ME81AH
connections: [["mac", "XX:XX:XX:XX:FF:FF"]]
temperature_command_topic: <your-id>/thermostat/set
temperature_command_template: >
{{ {'targetTemperature':value} | to_json }}
temperature_state_topic: <your-id>/thermostat/properties
temperature_state_template: >
{% if value_json is defined and value_json['targetTemperature'] is defined %}
{{ value_json['targetTemperature'] }}
{% endif %}
current_temperature_topic: <your-id>/thermostat/properties
current_temperature_template: >
{% if value_json is defined and value_json['temperature'] is defined %}
{{ value_json['temperature'] }}
{% endif %}
mode_state_topic: <your-id>/thermostat/properties
mode_state_template: >
{% if value_json is defined and value_json['deviceOn'] is defined %}
{% set deviceOn = value_json['deviceOn'] %}
{% else %}
{% set deviceOn = false %}
{% endif %}
{% if value_json is defined and value_json['schedulesMode'] is defined %}
{% set schedulesMode = value_json['schedulesMode'] %}
{% else %}
{% set schedulesMode = 'off' %}
{% endif %}
{% if deviceOn == true %}
{% if schedulesMode == 'auto' %}
auto
{% else %}
heat
{% endif %}
{% else %}
off
{% endif %}
action_topic: <your-id>/thermostat/properties
action_template: >
{% if value_json is defined and value_json['systemMode'] is defined %}
{% set deviceOn = value_json['deviceOn'] %}
{% else %}
{% set deviceOn = false %}
{% endif %}
{% if value_json is defined and value_json['systemMode'] is defined %}
{% set systemMode = value_json['systemMode'] %}
{% else %}
{% set systemMode = 'off' %}
{% endif %}
{% if deviceOn == true %}
{% if systemMode == 'cool' %}
idle
{% elif systemMode == 'heat' %}
heating
{% endif %}
{% else %}
off
{% endif %}
mode_command_topic: <your-id>/thermostat/set
mode_command_template: >
{% if value == 'auto' %}
{{ {'deviceOn':true,'schedulesMode':'auto'} | to_json }}
{% endif %}
{% if value == 'heat' %}
{{ {'deviceOn':true,'schedulesMode':'off'} | to_json }}
{% endif %}
{% if value == 'off' %}
{{ {'deviceOn':false,'schedulesMode':'off'} | to_json }}
{% endif %}
modes:
- "auto"
- "heat"
- "off"
temperature_unit: C
temp_step: 0.5
min_temp: 5
max_temp: 35
initial: 20
retain: true
qos: 0
Aditionally, I made changes to my previous automations which are doing the “hammering” of the values, until the desired value is set, with a random delay:
You just need to create two input_text helpers which save the desired temperature and value.
alias: House - Climate Set
description: Save Target Temperature with Helper
trigger:
- platform: event
event_type: call_service
event_data:
domain: climate
service: set_temperature
service_data:
entity_id: climate.living_thermostat
id: set_temp
- platform: event
event_type: call_service
event_data:
domain: climate
service: set_hvac_mode
service_data:
entity_id: climate.living_thermostat
id: set_mode
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: set_temp
sequence:
- service: input_number.set_value
target:
entity_id: input_number.climate_target_temp
data:
value: "{{ trigger.event.data.service_data.temperature }}"
- repeat:
until:
- condition: template
value_template: >-
{{ (states.input_number.climate_target_temp.state | int) ==
state_attr('climate.living_thermostat', 'temperature') }}
sequence:
- service: climate.set_temperature
data:
temperature: |
{{ trigger.event.data.service_data.temperature }}
target:
entity_id: climate.living_thermostat
- delay:
seconds: "{{ range(8, 11)|random|int }}"
- conditions:
- condition: trigger
id: set_mode
sequence:
- service: input_text.set_value
target:
entity_id: input_text.climate_mode
data:
value: "{{ trigger.event.data.service_data.hvac_mode }}"
- repeat:
until:
- condition: template
value_template: |-
condition: template
value_template: >-
{{ states.input_text.climate_mode.state == states.climate.living_thermostat.state }}
sequence:
- delay:
seconds: "{{ range(8, 11)|random|int }}"
- service: climate.set_hvac_mode
data:
hvac_mode: |
{{ trigger.event.data.service_data.hvac_mode }}
target:
entity_id: climate.living_thermostat
enabled: true
default: []
mode: restart
Just for clarification, I found the above automation somewhere on the forums, I just adapted it for my needs.
Let me know if you think if I should post a link of this discussion onto github.