| title is a filter function that capitalize the first letter of a sentence. It is needed because HA states are in lowercase (on/off) and Domoticz expects On or Off as per documentation Domoticz MQTT
As for the rest of your question, I don’t see how to improve your current code, except that if you have several climate entities I would replace:
"{{ state_attr('climate.thermostat_1', 'temperature') }}"
by
"{{ state_attr('climate.thermostat_' ~id , 'temperature') }}"
id would be extracted from the entity that triggered the automation. As an example see this snippet
- id: 69472b24-9c31-41f7-b324-b285fec1d7cf
alias: Chauffage PID
description: Pilotage des radiateurs par les thermostats PID
trigger:
- platform: state
id: command
entity_id:
- input_boolean.heater_command_id3
- input_boolean.heater_command_id4
- input_boolean.heater_command_id5
- input_boolean.heater_command_id6
- platform: state
id: climate
entity_id:
- climate.device_pid_id3 # salle de bains
- climate.device_pid_id4 # salle de bains amis
- climate.device_pid_id5 # chambre
- climate.device_pid_id6 # chambre amis
- platform: template
id: new_set_value
value_template: >
{{state_attr("climate.device_pid_id3", "temperature")}}
- platform: template
id: new_set_value
value_template: >
{{state_attr("climate.device_pid_id4", "temperature")}}
- platform: template
id: new_set_value
value_template: >
{{state_attr("climate.device_pid_id5", "temperature")}}
- platform: template
id: new_set_value
value_template: >
{{state_attr("climate.device_pid_id6", "temperature")}}
variables:
index:
"id3": "143:select" # commande radiateur salle de bains
"id4": "531:select" # commande radiateur salle de bains amis
"id5": "228:select" # commande radiateurs chambre
"id6": "229:select" # commande radiateurs chambre amis
id: "{{trigger.entity_id.split('_') | last }}" # entity index (id1, id2, ...)
idx: "{{index.get(id).split(':')[0]}}" # entity to control (dz idx) or climate entity
condition: []
action:
- if:
- condition: trigger
id: climate
- condition: template
value_template: >
{{states("climate.device_pid_" ~ id) == "off"}}
then:
- service: select.select_option
data:
option: "Off"
target:
entity_id: "select.{{idx}}"
else:
- condition: trigger
id: command
- if:
- condition: template
value_template: >
{{states("climate.device_pid_" ~ id) == "heat"}}
then:
# Command depends on difference between consigne et current in order to avoid switching off heaters constantly.
# Fil pilote 6 ordres: using Eco, -1° and -2°
# Fil pilote 4 ordres: using Eco only
# Off or HG is used only when target and consigne are very close
# TBD
- service: select.select_option
data:
option: >
{% if state_attr("climate.device_pid_" ~ id , "temperature") | float() > 8 %}
{% set cmd = "HG" %}
{% else %}
{% set cmd = "Off" %}
{% endif %}
{% if id == 5 or id == 6 %}
{{ iif(trigger.to_state.state == "on", "On", cmd) }}
{% else %}
{{ iif(trigger.to_state.state == "on", "On", cmd) }}
{% endif %}
target:
entity_id: select.{{idx}}
# - condition: trigger
# id: new_set_value
# - service: smart_thermostat.clear_integral
# data: {}
# target:
# entity_id: climate.device_pid_{{id}}
mode: parallel
max: 20