Disable automation rule on weekends

Hi all.

I have an automation rule set up to dim two LiFx lamps to 30% brightness and turn off another lamp at midnight every night.

I’d like to disable that automation rule on Saturdays and Sundays.

I’ve followed the guide here: https://www.home-assistant.io/integrations/workday to set up the binary_sensor.workday_sensor entity id, however I’m getting a bit confused on how to use it.

The bit that’s confusing me is the state entry, should that be on or off?

This is what I have at the moment:

- id: '1584587489169'
  alias: Dim the lights at midnight
  description: ''
  trigger:
  - at: 00:00
    platform: time
  condition:
  - condition: state
    entity_id: binary_sensor.workday_sensor
    state: 'off'
  action:
  - device_id: f6ce797b0c6c4262bd2ac43d377607bc5
    domain: light
    entity_id: light.dining_room_lamp
    type: turn_off
  - scene: scene.midnight

Any help greatly appreciated, thanks.

I don’t know, but since it is still Friday, go to developer tools -> states and look if binary_sensor.workday_sensor is on or off.

1 Like

At the moment it’s showing as on, so I guess the code is correct?

Yes, it is.

Ok thanks Francis :+1:

Sorry, you want this to not run at the weekend? At the moment, with the condition that the workday sensor is 'off', it will only run at the weekend. The automation will check that the conditions are true before proceeding, and binary_sensor.workday_sensor will only be 'off' on Saturday and Sunday. On weekdays, that condition will not be met and the action will not happen.

Also, I spot a potential race condition. If, at midnight, this automation is triggered and processed before the binary_sensor.workday state is updated, you could potentially have it not trigger first thing on a Saturday, but trigger first thing on a Monday.

Unless it’s super-critical that it occurs exactly at midnight, it may be safer to trigger at 00:01.

3 Likes

That’s a very good point, I didn’t even think of that.
I’ll change it to 00:01 just to be safe lol.

Thanks Troon :grinning:

Note that I’ve just edited my post: I think the condition is wrong.

Oh yeah I can see now, ok, I’ve just changed it to ‘on’ and to trigger at 00:01, hopefully that’ll do what I want lol.

Thanks again :+1:

2 Likes

Midnight has come and gone, the lights stayed on!

:+1: great success :+1:

2 Likes

The hint with the race condition was useful, i had an automation triggered at 00:00:00 with the condition workday on. But workday was updated at 00:00:28
image

Is it safe to use 00:01:00? Is the sensor updated every minute?
Can the update cycle be adapted?

Thank you in advance :smiley: