Sunset automation not working

Hi there,

Anyone spot something wrong here as it does not work?

- id: ID9
  alias: 'Pool Gate Open turn on light'
  trigger:
      platform: state
      entity_id: binary_sensor.door_window_sensor_158d00019fac86
      from: 'off'
      to: 'on'
  condition:
      condition: sun
      after: sunset
      before: sunrise
  action:
        service: switch.turn_on
        entity_id: switch.pool_light

Location and time are set correctly.

Secondly, is there a way inside the automation to turn it off after 1 minute or do I need to write a script to do this first? Any feedback would be appreciated.

You can’t be after sunset and before sunrise on the same day.


condition: or
conditions:
  - condition: sun 
    before: sunrise 
  - condition: sun 
    after: sunset 

To turn it off after a minute, add a delay, then the turn_off.

Oh, thank you! Does that mean the order of the condition statement you provided does not matter?

No, it’s just saying it’s either one or the other.

Thanks! Can’t have two action statements in one automation? How do I write the turn off statement without using a 2nd action?

action:
  - service: switch.turn_on
    entity_id: switch.pool_light
  - delay: 00:01:00 
  - service: switch.turn_off
    entity_id: switch.pool_light

Thank you so much but I’m getting config errors when I test this.

- id: ID9
  alias: 'Pool Gate Open turn on light'
  trigger:
      platform: state
      entity_id: binary_sensor.door_window_sensor_158d00019fac86
      from: 'off'
      to: 'on'
  condition: or
  conditions:
    - condition: sun
      before: sunrise
    - condition: sun
      after: sunset
  action:
    - service: switch.turn_on
      entity_id: switch.pool_light
    - delay: 00:01:00
    - service: switch.turn_off
      entity_id: switch.pool_light

Linter in Atom is saying the formatting is correct but I must have something astray?

Your trigger options are indented too far, and your condition declaration is missing (it’s painful syntax, but you need the declaration for the automation that there is a condition, and then you declare what the condition is, and the keyword for both is ‘condition’) , try this…

- id: ID9
  alias: 'Pool Gate Open turn on light'
  trigger:
    platform: state
    entity_id: binary_sensor.door_window_sensor_158d00019fac86
    from: 'off'
    to: 'on'
  condition:
    condition: or
    conditions:
      - condition: sun
        before: sunrise
      - condition: sun
        after: sunset
  action:
    - service: switch.turn_on
      entity_id: switch.pool_light
    - delay: 00:01:00
    - service: switch.turn_off
      entity_id: switch.pool_light

Thank you, seems to be fine now. Was formatting of the condition statement. YAML can be a challenge sometimes! Appreciate your help.

I had this:

condition: or
  conditions:
    - condition: sun
      before: sunrise
    - condition: sun
      after: sunset

and should of had this:

condition:
    condition: or
    conditions:
    - condition: sun
      before: sunrise
    - condition: sun
      after: sunset

:stuck_out_tongue_winking_eye:

Fun stuff :sunglasses:

Did the temperature difference template work from the other day, btw?

Working on that. Solar pump died and solar panel temp out sensor was reading 99C/210F so just steam was dribbling into the pool!!! Had to wire in the new higher flow rate pump in a hurry yesterday before everything melted! Hope to get onto your code in the next 24/48hrs.

Ha, rather you than me :wink::wink:

No worries, let me know how you get on :+1:

@anon43302295
Will do.

Don’t suppose I could ask another curly?

Replacing delay with input number thus:

timer_delay_slider:
    name: Delay Values
    initial: 20
    min: 5
    max: 120
    step: 5
    icon: mdi:camera-timer

And then adding this to automation but config throws up an error:

- delay '00:{{ states.input_number.timer_delay_slider.state | int }}:00'

When I use the template editor and enter '00:{{ states.input_number.timer_delay_slider.state | int }}:00', it returns a valid number '00:20:00' but the automation does not like it.

Trying this now - delay 00:00:{{ states.input_number.timer_delay_slider.state | int }} which returns the correct value 00:00:20 but the config checker does not like it. Odd, because if I enter - delay 00:00:20, it’s happy.

You need a colon after delay.

Ah, caught out again! Thank you. How do I covert the value 120 into 2 minutes? It presents as 00:00:120 currently.

Umm, well…

1 - You could do a massively complicated template that works out if the number is over 60 and converts the delay in to minutes and seconds.

Or,

2 - you could add a second slider for minutes, and put that in to the minutes bit of the delay template in the same way as you have the seconds.

Obviously 2 is a lot quicker and easier, but might not be quite so polished if you have a specific desire for how the front end represents it.

I’ve just woken up, so if you want to do number 1 you’ll have to give me a couple of hours :joy:

Thanks, appreciated. It might be real handy for everyone to have something like that (option 1) but for now, I’ll just limit my delay to a max of 59 seconds. Enjoy your day. My bed time!

Yeah, I’ll take a punt at it when my eyes are open :+1:

1 Like