Automation doesn't seem to trigger

Hello, I am now to Home Assistant but already enjoying it. I have some automations set up (for example, lights on when I come home). But the following one doesn’t seem to trigger. It is in the morning when I wake up, that the livingroom lights turn on at a set time (06:30) but only if certain conditions are met. I tried to compare them with the other automations (which do work) but can’t find anything wrong with it.

The slides are set to:

  • sl_wu_hr: 6
  • sl_wu_mn: 30

configuration section:

binary_sensor:
  - platform: workday
    name: Workday Morning
    country: UK

  sl_wu_hr:
    name: Wake-up Hrs
    min: 0
    max: 23
    step: 1

  sl_wu_mn:
    name: Wake-up Min
    min: 0
    max: 55
    step: 5

Automation section:

id: livingroom_lights_on_on_workdays
  alias: Livingroom light ON on workdays morning
  trigger:
    platform: template
    value_template: '{{ now.time().strftime("%-H") == states.input_number.sl_wu_hr.state and now.time().strftime("%-M") == states.input_number.sl_wu_mn.state }}'
  condition:
    condition: and
      conditions:
      - condition: state
        entity_id: 'binary_sensor.workday_morning'
        state: 'on'
      - condition: sun
        before: sunrise
        before_offset: "+1:00:00"
      - condition: or
          conditions:
          - condition: state
            entity_id: device_tracker.stephan
            state: 'home'
          - condition: state
            entity_id: device_tracker.catherine
            state: 'home'
  action:
    service: homeassistant.turn_on
    entity_id: group.lights_livingroom

now.time().strftime("%-H")

change to

now().hour

and

now.time().strftime("%-M")

to

now().minute

1 Like

Basically, you were comparing a string to a number. Your other option would have been to convert your string to an integer using | int:

now.time().strftime("%-H") | int

This is assuming now.time().strftime("%-H") is the correct syntax. I’ve never used that method, so I don’t know if its correct. I do know that strfttime always returns strings in python, I would assume its the same here.

1 Like

After some digging been able to find the solution. There were 2 issues:

  1. The template was incorrect
  2. Can’t trigger on a template where values are not changing

My final automation sections looks like this:

- id: livingroom_lights_on_on_workdays                                                                                                                                                        
  alias: Livingroom light ON on workdays morning                                                                                                                                              
  trigger:                                                                                                                                                                                    
    platform: time                                                                                                                                                                            
    minutes: '/5'                                                                                                                                                                             
    seconds: 0                                                                                                                                                                                
  condition:                                                                                                                                                                                  
  condition: and                                                                                                                                                                            
    conditions:                                                                                                                                                                               
    - condition: template
      value_template: "{{ now().hour == states('input_number.sl_wu_hr_morning') | int and now().minute == states('input_number.sl_wu_mn_morning') | int }}"
    - condition: state                                                                                                                                                                      
      entity_id: 'binary_sensor.workday_morning'
      state: 'on'                                                                                                                                                                           
    - condition: sun                                                                                                                                                                        
      before: sunrise
      before_offset: "+1:00:00"  
    - condition: or                                                                                                                                                                         
      conditions:
      - condition: state                                                                                                                                                                    
        entity_id: device_tracker.stephan                                                                                                                                                   
        state: 'home'                                                                                                                                                                       
      - condition: state                                                                                                                                                                    
        entity_id: device_tracker.catherine                                                                                                                                                 
        state: 'home'
  action:
    service: homeassistant.turn_on
    entity_id: group.lights_livingroom

nice work, looks good.

1 Like