I have a light on a Tuya plug for my fish tanks that I have been using an automation to turn off 1hr before sunset, however as the nights are closing in this is now triggering around 14:50. I’d like to set a minimum turn off time at 16:00.
I’ve seen similar issues but the other way around, where a light turns on at sunset or a time, typically the condition that occurs first triggers the action, but I need the latter event to trigger the action, so far nothing I’ve tried works.
This is what I’ve tried and how I’ve interpreted what it’s supposed to do:
My initial test - Turn off the lights 1hr before sunset but only after 16:00
(I can see why this doesn’t work because sunset is not occurring after 16:00)
- id: '1600967437672'
alias: 'Fish: Fish Lights off'
description: ''
trigger:
- event: sunset
offset: -01:00:00
platform: sun
condition:
- condition: time
after: '16:00'
action:
- device_id: 2b23566d5e4640c09e1cde310f1c9605
domain: switch
entity_id: switch.32066407cc50e3d46c9e_4
type: turn_off
mode: single
When the sun’s elevation is below 3.5 turn off the lights, but only when the time is after 16:00
(I don’t see why this doesn’t work because the sun’s elevation is below 3.5 at 16:00 in the winter)
- id: '1607474680677'
alias: 'Fish: Fish Lights Off Elevation'
description: ''
trigger:
- platform: numeric_state
entity_id: sun.sun
attribute: elevation
below: '3.5'
condition:
- condition: time
after: '16:00:00'
action:
- type: turn_off
device_id: 2b23566d5e4640c09e1cde310f1c9605
entity_id: switch.32066407cc50e3d46c9e_4
domain: switch
mode: single
Set the status of a boolean to off (which in turn triggers the lights) 1hr before sunset but only after 16:00 and whilst the boolean is set to on, check every 10 minutes.
- id: '1607679428050'
alias: 'Boolean Trigger: Fish Lights off'
description: ''
trigger:
- event: sunset
offset: -01:00:00
platform: sun
- platform: time_pattern
minutes: '10'
condition:
- condition: and
conditions:
- condition: time
after: '16:00:00'
weekday:
- mon
- tue
- wed
- thu
- fri
- sat
- sun
- condition: state
entity_id: input_boolean.fishlight_status
state: 'on'
action:
- service: input_boolean.turn_off
data: {}
entity_id: input_boolean.fishlight_status
mode: single
I also want to be able to override this behaviour and turn the lights on/off manually in the evening (when cleaning the fish tanks) so I don’t want the turn off event to keep triggering whenever the sun’s elevation or time updates (hence the boolean helper).
How can I best handle this?