Can I use template in from: state trigger?

Hi,
I’m implementing “away_mode”, basically controlled by external button.
The logic is simple: when helper “away_mode” is on, automation sets climate temperature to numeric helper eco_temp, and when off, to numeric helper “boost_temp” (plus some lights controll) - easy. But I want to turn off “away_mode” on any manual climate temperature change. The problem is when “away_mode” is set to on, it changes climate temperature, wchich turns “away_mode” back off :frowning:
So I try to filter only manual climate temperature changes - it can be done by condition on temperature change trigger from: (eco_temp). And actually it works OK when I put temperature directly in automation.
But I can’t manage to put helper value instead of direct value.

My automation:

alias: Termostat lab away mode
description: ""
trigger:
  - platform: state
    entity_id:
      - climate.lab
    attribute: temperature
    id: temp
    from:
      value_template: "{{states('input_number.heating_eco_temp')|float}}"  #Does not work, but "17.0" works ok.
  - platform: state
    entity_id:
      - input_boolean.lab_away_mode
condition: []
action:
  - if:
      - condition: trigger
        id: temp
    then:
      - condition: state
        entity_id: input_boolean.lab_away_mode
        state: "on"
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id: input_boolean.lab_away_mode
    else:
      - if:
          - condition: state
            entity_id: input_boolean.lab_away_mode
            state: "on"
        then:
          - service: climate.set_temperature
            data_template:
              temperature: "{{states('input_number.heating_eco_temp')|float}}"
              entity_id: climate.lab
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.lab_lights_2
        else:
          - service: climate.set_temperature
            data_template:
              temperature: "{{states('input_number.heating_boost_temp')|float}}"
              entity_id: climate.lab
          - if:
              - condition: state
                entity_id: sensor.controller1_light_level
                state: ">10"
            then:
              - service: light.turn_on
                data:
                  brightness: 206
                target:
                  entity_id: light.midesklamp1s_67ca
mode: single

So my question is, how to template from: in trigger, or can I achieve such logic in other way?

No, templates are not supported there. Your description of the larger issue is a bit confusing, if you can clarify what you are trying to do we can probably point you in the right direction.

Right, let’s keep it simple.
Main goal of this automation is to control climate.lab temperature by input_boolean.lab_away_mode, setting temperature to value of input_number.heating_eco_temp when input_boolean.lab_away_mode is on, and to input_number.heating_boost_temp when off.
This part works OK.
Additionaly I want to turn off input_boolean.lab_away_mode anytime climate.lab temperature is changed BUT NOT when it is changed by turning on input_boolean.lab_away_mode (literaly, changed by this automation).

My attempt is based on logic that in fact I need to turn off input_boolean.lab_away_mode ONLY when temperature it is changed FROM input_number.heating_eco_temp, because for other temperature values input_boolean.lab_away_mode should be off already. It works, but as you mentioned, I can only hardcode FROM temperature, I can’t use helper value input_number.heating_eco_temp

I hope I’m clear this time, can you find other approach to achieve this logic?

If I’m understanding you correctly, I think the following covers what you have described:

alias: Termostat lab away mode
description: ""
trigger:
  - platform: state
    entity_id:
      - climate.lab
    attribute: temperature
    id: temp
  - platform: state
    entity_id:
      - input_boolean.lab_away_mode
    to:
      - on
      - off
    from:
      - on
      - off
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: temp
          - condition: template
            value_template: >
              {{trigger.from_state.attributes.temperature == 
              states('input_number.heating_eco_temp') | float}}
          - condition: state
            entity_id: input_boolean.lab_away_mode
            state: "on"
        sequence:
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id: input_boolean.lab_away_mode  
      - conditions:
          - condition: state
            entity_id: input_boolean.lab_away_mode
            state: "on"
        sequence:
          - service: climate.set_temperature
            data:
              temperature: "{{states('input_number.heating_eco_temp') | float}}"
            target:
              entity_id: climate.lab
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.lab_lights_2
    default:
      - service: climate.set_temperature
        data:
          temperature: "{{states('input_number.heating_boost_temp') | float}}"
        target:
          entity_id: climate.lab
      - condition: numeric_state
        entity_id: sensor.controller1_light_level
        above: "10"
      - service: light.turn_on
        data:
          brightness: 206
        target:
          entity_id: light.midesklamp1s_67ca
mode: single
1 Like

Thank you @Didgeridrew, sorry for late response, but I didn’t get notification about your post.
Yes, that’s it! Instead of template in trigger from value, I can use template in action condition with trigger.from_state, and it solves my case :slight_smile: