IF then Action depending on time

Hi guys,

I already had home assistant installed long time ago and already forgot everything :frowning_face:
Unfortunately I haven’t saved my config so I need to do everything from scratch.

What do I want to achieve?
IF
single click on a Xiaomi switch
then
Light 1, light 2 and light 3 should switch on
after 2 minutes
Light 1, light 2 and light 3 should
switch off if between 05:00 and 18:00
or
switch to ‘moonlight’ mode if between 18:01 and 04:59

I assume it is pretty easy but can’t find out by my own.

Anyone can help?

Check “Responding to button clicks” section here https://www.zigbee2mqtt.io/integration/home_assistant.html

Hope it helps you out :slight_smile:

Thanks for your quick response.

Unfortunately this is not helping as this only describes the core functionality of button clicks.
I’m familiar how to use button click and actions but not how to include a timer and depending on the current time at least two different actions…

I guess you will need three automations since you want to do different things depending on time of the day.

This should help you get started.

 trigger:
   platform: state
   entity_id: sensor.my_switch_click
   to: 'single'
 condition:
   condition: time
   after: '05:00:00'
   before: '18:00:00'
 action:

@claha is there no “loop” solution to get this done?
Of course I can create three automations but would like to avoid this.

Maybe you can use some templating (https://www.home-assistant.io/docs/configuration/templating/). I’ve tried that in the past but it just gets messy in my opinion. I’ve moved some of my more complicated stuff to python_scripts (https://www.home-assistant.io/components/python_script/). So just trigger the script when button is clicked, there you can easily do loops and ifs :grin:

I think it is possible to implement as a 1 template-based automation:
single click on a Xiaomi switch - trigger of your automation (have no experience with Xiaomi)

just service light.turn_on with a list of lights

delay

here’s the messy tempting bit.
don’t know what’s ‘moonlight’ mode and it’s crucial here, can you elaborate?