I’m trying to disable manual control of radiators.
So if the switch is turned on when the climate entity is in idle then it should turn off the switch. And vice versa.
Kitchen (kok) and livingroom (is the same room that’s why I need the if else).
alias: "Element av om man styr manuellt "
description: Styrning av smart plug manuellt rättas till.
trigger:
- platform: state
entity_id:
- switch.element_david_switch
- switch.element_matilda_switch
- switch.element_sovrum_switch
- switch.element_kok_switch
- switch.element_vardagsrum_switch
from: "off"
to: "on"
id: off-on
- platform: state
entity_id:
- switch.element_david_switch
- switch.element_matilda_switch
- switch.element_sovrum_switch
- switch.element_kok_switch
- switch.element_vardagsrum_switch
from: "on"
to: "off"
id: on-off
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- off-on
- condition: template
value_template: |-
{%- if "kok" in trigger.entity_id -%}
{{ state_attr("climate.vardagsrum", 'hvac_action') == "idle" }}
{%- else -%}
{{ state_attr("climate." ~ trigger.entity_id.replace("switch","").replace("_","").replace(".element",""), 'hvac_action') == "idle" }}
{%- endif -%}
sequence:
- service: switch.turn_off
target:
entity_id: "{{ trigger.entity_id }}"
data: {}
- service: tts.cloud_say
metadata: {}
data:
entity_id: media_player.hela_huset
message: >-
Det är snällt att ni vill hjälpa mig med att styra värmen i
lägenheten, men jag klarar det bra själv. Tack ändå.
language: sv-SE
cache: false
- conditions:
- condition: trigger
id:
- on-off
- condition: template
value_template: |-
{% if "kok" in trigger.entity_id %}
{{ state_attr("climate.vardagsrum", 'hvac_action') == "heating" }}
{% else %}
{{ state_attr("climate." ~ trigger.entity_id.replace("switch","").replace("_","").replace(".element",""), 'hvac_action') == "heating" }}
{% endif %}
sequence:
- service: switch.turn_on
target:
entity_id: "{{ trigger.entity_id }}"
data: {}
- service: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.hela_huset
message: >-
Det är snällt att ni vill hjälpa mig med att styra värmen i
lägenheten, men jag klarar det bra själv. Tack ändå.
language: sv-SE
mode: single
When I test the template in developer tools I get this:
{% set trigger = "switch.element_vardagsrum_switch" %}
{% if "kok" in trigger %}
{{ state_attr("climate.vardagsrum", 'hvac_action') == "idle" }}
{% else %}
{{ state_attr("climate." ~ trigger.replace("switch","").replace("_","").replace(".element",""), 'hvac_action') == "idle" }}
{% endif %}
Climate is:
{{ state_attr("climate." ~ trigger.replace("switch","").replace("_","").replace(".element",""), 'hvac_action') }}
Why does it allow me to turn on the switch even though the climate entity is in idle?
The condition in the left lane is just a condition I tested with but it removed.