State Trigger template

Hi all,

I am going crazy here. I want my input select changed once the attribute fan_mode of my climate.xxx entity changes.

the inut_select should be equal the fan_mode. The action works fine but the trigger does not.

any idea… here you go for the automation:

  - alias: Set input select mode
    initial_state: true
    trigger:
      platform: template
      value_template: "{{ state_attr('climate.air_conditioner_bedroom', 'fan_mode') }}"
    action:
      service: input_select.select_option
      data_template:
        entity_id: input_select.climate_fan_speed_bedroom
        option: "{{ state_attr('climate.air_conditioner_bedroom', 'fan_mode') }}"

Okay your template trigger needs to render true or false
Currently its not.
You should change the trigger to a state

Using this trigger:

   trigger:
     platform: state
     entity_id: climate.air_conditioner_bedroom

Will work but it will trigger a lot more often than it has to (when attributes other than the fan mode change).

So you could create a template sensor that extracts the fan mode and use that:

sensor:
- platform: template
  sensors:
    fan_mode:
      friendly_name: "Fan Mode"
      entity_id: climate.air_conditioner_bedroom
      value_template: "{{ state_attr('climate.air_conditioner_bedroom', 'fan_mode') }}"

Your trigger then becomes:

   trigger:
     platform: state
     entity_id: sensor.fan_mode

It could be done without the extra sensor, but I agree this is probably the best way. Also makes the action part a bit simpler:

    action:
      service: input_select.select_option
      data_template:
        entity_id: input_select.climate_fan_speed_bedroom
        option: "{{ trigger.to_state.state }}"

Just out of interest, how would you do it Phil?

Now that I’ve seen your answer, I’d do it that way! :smiley:

To do it just in the automation (i.e., without the template sensor):

- trigger:
  - platform: state
    entity_id: climate.air_conditioner_bedroom
  condition:
  - condition: template
    value_template: >
      {{ trigger.from_state is none or
         trigger.to_state is not none and
         trigger.from_state.attributes.fan_mode !=
         trigger.to_state.attributes.fan_mode }}
  action:
  - service: input_select.select_option
    entity_id: input_select.climate_fan_speed_bedroom
    data_template:
      option: "{{ trigger.to_state.attributes.fan_mode }}"

That makes sense. Thank you.

@tom_l @pnbruckner

This is mine
But I use node red
i know its not perfect but it works what are your thoughts

[{"id":"9c95bfce.5a9dc","type":"tab","label":"Daikin Skyzone","disabled":false,"info":""},{"id":"dd301840.01e338","type":"server-state-changed","z":"9c95bfce.5a9dc","name":"","server":"ef392d83.86c5a","version":1,"entityidfilter":"input_select.daikin_mode","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":220,"y":40,"wires":[["35feaf63.77c5a"]]},{"id":"11c8497.54369b7","type":"api-call-service","z":"9c95bfce.5a9dc","name":"set_hvac_mode-{\"hvac_mode\":payload}","server":"ef392d83.86c5a","version":1,"debugenabled":false,"service_domain":"climate","service":"set_hvac_mode","entityId":"climate.daikin_skyzone","data":"{\"hvac_mode\":payload}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":true,"x":980,"y":100,"wires":[[]]},{"id":"14134eab.29c2c1","type":"server-state-changed","z":"9c95bfce.5a9dc","name":"","server":"ef392d83.86c5a","version":1,"entityidfilter":"climate.daikin_skyzone","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":210,"y":100,"wires":[["e9b8f8f7.7c3068"]]},{"id":"d653754.17c3788","type":"api-call-service","z":"9c95bfce.5a9dc","name":"Auto","server":"ef392d83.86c5a","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.daikin_mode","data":"{\"option\":payload}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":690,"y":100,"wires":[[]]},{"id":"b6a292c9.c923e","type":"change","z":"9c95bfce.5a9dc","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"Auto","fromt":"str","to":"auto","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"Cool","fromt":"str","to":"cool","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"Heat","fromt":"str","to":"heat","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"Fan Only","fromt":"str","to":"fan_only","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"Dry","fromt":"str","to":"dry","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":60,"wires":[["11c8497.54369b7"]]},{"id":"e9b8f8f7.7c3068","type":"change","z":"9c95bfce.5a9dc","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"auto","fromt":"str","to":"Auto","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"cool","fromt":"str","to":"Cool","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"heat","fromt":"str","to":"Heat","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"Off","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"fan_only","fromt":"str","to":"Fan Only","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"dry","fromt":"str","to":"Dry","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":100,"wires":[["d653754.17c3788"]]},{"id":"8b1cc403.080df8","type":"api-call-service","z":"9c95bfce.5a9dc","name":"turn_off","server":"ef392d83.86c5a","version":1,"debugenabled":false,"service_domain":"climate","service":"turn_off","entityId":"climate.daikin_skyzone","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":true,"x":900,"y":40,"wires":[["26790a05.5aff86"]]},{"id":"35feaf63.77c5a","type":"switch","z":"9c95bfce.5a9dc","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Off","vt":"str"},{"t":"neq","v":"Off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":40,"wires":[["8b1cc403.080df8"],["b6a292c9.c923e"]]},{"id":"e8b5217f.efff2","type":"server-state-changed","z":"9c95bfce.5a9dc","name":"","server":"ef392d83.86c5a","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_select.daikin_fan_mode","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":230,"y":220,"wires":[["811f8aa2.5710a8"]]},{"id":"811f8aa2.5710a8","type":"api-call-service","z":"9c95bfce.5a9dc","name":"set_hvac_mode-{\"hvac_mode\":payload}","server":"ef392d83.86c5a","version":1,"debugenabled":false,"service_domain":"climate","service":"set_fan_mode","entityId":"climate.daikin_skyzone","data":"{\"fan_mode\":payload}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":true,"x":600,"y":220,"wires":[[]]},{"id":"2bb0a685.08c2aa","type":"server-state-changed","z":"9c95bfce.5a9dc","name":"","server":"ef392d83.86c5a","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"climate.daikin_skyzone","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":210,"y":280,"wires":[["8aeee73.65b2118"]]},{"id":"b3741234.03628","type":"api-call-service","z":"9c95bfce.5a9dc","name":"Auto","server":"ef392d83.86c5a","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.daikin_fan_mode","data":"{\"option\":payload}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1190,"y":280,"wires":[[]]},{"id":"26790a05.5aff86","type":"change","z":"9c95bfce.5a9dc","name":"Fan Mode N/A  ","rules":[{"t":"set","p":"payload","pt":"msg","to":"N/A","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":40,"wires":[["b3741234.03628"]]},{"id":"8aeee73.65b2118","type":"api-render-template","z":"9c95bfce.5a9dc","name":"Template from HA","server":"ef392d83.86c5a","template":"{{ state_attr('climate.daikin_skyzone', 'fan_mode') }}","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":570,"y":280,"wires":[["b3741234.03628"]]},{"id":"ef392d83.86c5a","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Actually I’m using exactly this. And it’s working fine .thanks a lot for all your answers …was freaking out as I didn’t know that state change also listens for the attributes