Help with a custom sensor automation

Hi all
probably I am missing something obvious but here it is.
I have the following automation which today at 05:45 the value was 13.8

- id: inpout time Morning Temperature for covers when sun and cold
  alias: input Morning Temperature for covers when sun and cold
  trigger:
    - platform: time
      at: '05:45:00'

  action:
    service: input_number.set_value
    data:
      value: "{{ states('sensor.outdoor_temperature_2') | float }}"
    entity_id: input_number.temperature_for_covers
    

I have the following sensor which right now the it’s value is 8

- platform: template
  sensors:
      temp_diff_out_morning:
        friendly_name: "temp diff outdoor morning for covers"
        value_template: "{{states.sensor.outdoor_temperature_2.state|round|int-states.input_number.temperature_for_covers.state|round|int}}"

and the following trigger in my automation which is not working.
The idea is to first mark what is the outside temperature early in the morning
and if the outside temperature gets warmer (meaning its sunny) to open the covers in the living room.
But something in the below trigger is wrong and it is not triggering the automation.
Any ideas what is wrong?

- id: Open Covers in winter
  trigger:
    platform: numeric_state
    entity_id: sensor.temp_diff_out_morning
    value_template: "{{states.sensor.outdoor_temperature_2.state|round|int-states.input_number.temperature_for_covers.state|round|int}}"
    above: 1

  condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: 
          - cover.50758014840d8e91f4fd
          - cover.50758014840d8e91f036
        state: 'unknown'
      - condition: state
        entity_id: 
          - cover.50758014840d8e91f4fd
          - cover.50758014840d8e91f036
        state: 'closing'
      - condition: state
        entity_id: 
          - cover.50758014840d8e91f4fd
          - cover.50758014840d8e91f036
        state: 'open'    
  - condition: time
    after: '06:00:00'
    before: '10:30:00'
  - condition: state
    entity_id: alarm_control_panel.mqtt_alarm
    state: "disarmed"        
  - "{{ trigger.for.seconds == 1 * 60 and now().month in [1, 2, 3, 4, 5, 10, 11, 12] }}"
        
  action:
    - service: cover.open_cover
      entity_id: 
        - cover.50758014840d8e91f4fd # main window
        - cover.50758014840d8e91f036 # erker
    - service: input_number.set_value
      data:
        value: "-20"
      entity_id: input_number.temperature_for_covers  

I havent checked all the lines but the first thing I noticed was the trigger. Please try using the below trigger instead of one you have.

trigger:
  - platform: template
    value_template: >-
      {{states('sensor.outdoor_temperature_2')|int|round - states('input_number.temperature_for_covers')|int|round
      > 1}}

I just tried it, with >8 and it is not working.

Although the following template returns true the automation is not triggered.

value_template: >-
      {{states('sensor.outdoor_temperature_2')|int|round - states('input_number.temperature_for_covers')|int|round
      > 1}}  

Any ideas what is wrong?

That would be the conditions. Did you check them? what is this condition?

- "{{ trigger.for.seconds == 1 * 60 and now().month in [1, 2, 3, 4, 5, 10, 11, 12] }}"

These are the months I want the automation to run. The conditions are ok I think because before the previous trigger was a simple one as “if outside temperature is above 17 then “run”” and it was working fine with the same conditions. I really don’t understand why this is not working

probably you have a point here.
i think I have to add

for:
  minutes: 1

in the above trigger to make it work

Also the last template condition should look like this.

- condition: template
    value_template: >-
      {{ trigger.for.seconds == 1 * 60 and now().month in [1, 2, 3, 4, 5, 10,
      11, 12] }}
1 Like

Thanks, I will do some testing and let you know