Simple automation on/off hallway lamp

I made an automation for the upstairs hallway, but I can’t make it work the way I like it.
The setup is simple. A lamp that can be operated by 2 action switches.

The following is what I have in mind, and it works that way.
During the day the light is on for 100% (day mode)
After sunset the light is on for 30% and switches off automatically after 5 minutes (night mode)
After a double-click the light is always on at 100% (day / night mode)

What I can’t figure out is “night mode”.
If the switch is pressed once during the night mode, you always have to wait 5 minutes before the automation is released.
Can this be accomplished in any other way?

Here is my automation:

alias: Overloop verlichting
description: Overdag of na "dubbel-klik" altijd 100%; Zon onder -> 30%
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/overloop-1
  - platform: mqtt
    topic: zigbee2mqtt/overloop-2
condition:
  - condition: template
    value_template: '{{ trigger.payload_json["action"] in ["single", "double"] }}'
action:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: template
                value_template: '{{ trigger.payload_json["action"] == "double" }}'
              - condition: sun
                before: sunset
                after: sunrise
        sequence:
          - service: light.toggle
            target:
              entity_id: light.overloop
            data:
              brightness_pct: 100
      - conditions:
          - condition: template
            value_template: '{{ trigger.payload_json["action"] == "single" }}'
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.overloop
            data:
              brightness_pct: 30
          - delay:
              hours: 0
              minutes: 5
              seconds: 0
              milliseconds: 0
          - service: light.turn_off
            target:
              entity_id: light.overloop
            data: {}
    default: []
mode: single

The first thing that comes to mind is the “wrong” use of the sun component. You can’t use before and after in one condition, that needs two. :wink:

Conditions - Home Assistant

Therefore, to cover time between sunset and sunrise one need to use after: sunset and before: sunrise as 2 separate conditions and combine them using or.

“after: sunrise” and “before: sunset” in one condition is possible and means the sun is above the horizon (day-time).
The “issue” I have is the 5 minutes waiting time… in this period I can’t use the automation.

If you think so, good luck! :slight_smile:

Change this:

mode: single

to this:

mode: restart

When the automation is triggered while a previous delay is counting down, mode: restart means the automation’s action will be restarted. In other words, the previous delay is cancelled and the action is executed.

Great. Thank you. It works now.

1 Like