zamzon
(Mads)
April 24, 2020, 7:42pm
1
I would like to merge my two automations in to one, but i need to know which entity that trigger to run the correct action. My two automations works fine separate
the first automation:
When my setpoint is changed in my IHC system, set the temperarure in my climate in HA
- id: '1587674585478'
alias: clima stue sync ihc to ha
description: ''
trigger:
- event_data:
entity_id: sensor.temperatur_stue_setpoint
event_type: state_changed
platform: event
condition:
- condition: template
value_template: '{{ states(''sensor.temperatur_stue_setpunkt'') != states(''temperatur_stue_sensor.setpunkt2'')
}}'
action:
- data_template:
temperature: '{{ states(''sensor.temperatur_stue_setpunkt'') }}'
entity_id: climate.stue
service: climate.set_temperature
Automation two:
When I set the temperature in HA, sync the setpoint to my IHC system.
- id: '1586809820067'
alias: climate stue sync HA til IHC
description: ''
trigger:
- event_data:
entity_id: sensor.temperatur_stue_setpunkt2
event_type: state_changed
platform: event
condition:
- condition: template
value_template: '{{ states(''sensor.temperatur_stue_setpunkt'') != states(''sensor.temperatur_stue_setpunkt2'')
}}'
action:
- data_template:
ihc_id: 29324564
value: '{{ states.climate.stue.attributes.temperature }}'
service: ihc.set_runtime_value_float
my thought was something like this, I know this dosen’t work, but I hope this makes sense for what I want to do.
- id: '1587674585478'
alias: clima sync both ways
description: ''
trigger:
- event_data:
entity_id: sensor.setpunkt
event_type: state_changed
platform: event
- event_data:
entity_id: sensor.setpunkt2
event_type: state_changed
platform: event
condition:
- condition: template
value_template: '{{ states(''sensor.setpunkt'') != states(''sensor.setpunkt2'')
}}'
action:
service_template: >
{% if trigger.entity_id.name == "sensor.setpunkt" %}
- data_template:
temperature: '{{ states(''sensor.setpunkt'') }}'
entity_id: climate.stue
service: climate.set_temperature
{% elif trigger.entity_id.name == "sensor.setpunkt2" %}
- data_template:
ihc_id: 29324564
value: '{{ states.climate.stue.attributes.temperature }}'
service: ihc.set_runtime_value_float
{% endif %}
I’m not sure I fully understand your two automations, but given what they are, and you say they do what you want, then this should be equivalent:
- trigger:
- platform: state
entity_id:
- sensor.setpoint
- sensor.setpunkt
condition:
- condition: template
value_template: "{{ states('sensor.setpunkt') != states('sensor.setpunkt2') }}"
action:
- service: climate.set_temperature
entity_id: climate.stue
data_template:
temperature: "{{ states('sensor.setpunkt') }}"
But your attempt at combining them seems to try to do something completely different.
popboxgun
(ha_popbox)
April 24, 2020, 8:32pm
3
Looks like you pasted the same automation twice so I think this is what your trying to do.
Since your using two different services with different arguments you will need to pass them to scripts.
Automation:
- id: '1587674585478'
alias: clima sync both ways
description: ''
trigger:
- event_data:
- entity_id: sensor.setpunkt
- entity_id: sensor.setpunkt2
event_type: state_changed
platform: event
condition:
- condition: template
value_template: '{{ states(''sensor.setpunkt'') != states(''sensor.setpunkt2'') }}'
action:
service_template: >-
{% if trigger.entity_id == 'sensor.setpunkt' %}
script.setpunkt_climate_set_temperature
{% elif trigger.entity_id == 'sensor.setpunkt2' %}
script.setpunkt2_ihc_set_runtime_value_float
{% endif %}
data_template:
entity_id: climate.stue
temperature: '{{ states(''sensor.setpunkt'') }}'
value: '{{ states.climate.stue.attributes.temperature }}'
ihc_id: 29324564
Script:
setpunkt_climate_set_temperature:
sequence:
- service: climate.set_temperature
data_template:
temperature: "{{ temperature }}"
entity_id: "{{ entity_id}}"
setpunkt2_ihc_set_runtime_value_float:
sequence:
- service: ihc.set_runtime_value_float
data_template:
value: "{{ value }}"
ihc_id: "{{ ihc_id}}"
petro
(Petro)
April 25, 2020, 2:27am
4
Using dot notation for an object_id is very risky. You won’t be able to access the items from the state machines states object.
popboxgun
(ha_popbox)
April 25, 2020, 11:27am
5
Yes, that was a copy/paste error, I have fixed it.
zamzon
(Mads)
April 28, 2020, 6:32pm
6
Thanks
I did try to use it, and found out the missing % at setpoint2.
but I get an error in the data_template action
data_template: >-
entity_id: climate.stue
temperature: '{{ states(''sensor.setpunkt'') }}'
value: '{{ states.climate.stue.attributes.temperature }}'
ihc_id: 29324564
Message malformed: expected a dictionary for dictionary value @ data['action'][0]['data_template']
I did correct my two automations so you can see the what they do
popboxgun
(ha_popbox)
April 28, 2020, 6:42pm
7
I left out a % in this line
{% elif trigger.entity_id == 'sensor.setpunkt2' %}
popboxgun
(ha_popbox)
April 28, 2020, 6:55pm
8
I don’t think the >- is actually needed after the data_template:
zamzon
(Mads)
April 28, 2020, 7:38pm
10
I can run my automation, but my script does not run
popboxgun
(ha_popbox)
April 29, 2020, 12:16am
11
By run your script, you mean manually? Try turning up the logging on the script. You should see it execute in the logs.
Put this in your configuration.yaml
homeassistant.helpers.script: info
zamzon
(Mads)
April 29, 2020, 4:37am
12
No
I can see in the UI when I change my setpunkt entity my automation runs, but when I go to the script tab it hasn’t run any of the two scripts.
popboxgun
(ha_popbox)
April 29, 2020, 12:55pm
13
If you manually run the automation from developers tools, it will ignore the condition.
zamzon
(Mads)
April 29, 2020, 8:22pm
14
I did try doing it manually, but with no luck, it wont start the scripts
Here is how my automation looks now
- id: '15876745854767888'
alias: clima sync both ways
description: ''
trigger:
- event_data:
entity_id: sensor.temperatur_stue_setpunkt
event_type: state_changed
platform: event
- event_data:
entity_id: sensor.temperatur_stue_setpunkt2
event_type: state_changed
platform: event
condition:
- condition: template
value_template: '{{ states(''sensor.temperatur_stue_setpunkt'') != states(''sensor.temperatur_stue_setpunkt2'') }}'
action:
service_template: >-
{% if trigger.entity_id == 'sensor.temperatur_stue_setpunkt' %}
script.setpunkt_climate_set_temperature
{% elif trigger.entity_id == 'sensor.temperatur_stue_setpunkt2' %}
script.setpunkt2_ihc_set_runtime_value_float
{% endif %}
data_template:
entity_id: climate.stue
temperature: '{{ states(''sensor.temperatur_stue_setpunkt'') }}'
value: '{{ states.climate.stue.attributes.temperature }}'
ihc_id: 29324564
Scripts:
setpunkt_climate_set_temperature:
sequence:
- service: climate.set_temperature
data_template:
temperature: '{{ temperature }}'
entity_id: '{{ entity_id}}'
setpunkt2_ihc_set_runtime_value_float:
sequence:
- service: ihc.set_runtime_value_float
data_template:
value: '{{ value }}'
ihc_id: '{{ ihc_id}}'