Shelly Dimmer SW1 input AND Time of Day controls Automations

Tags: #<Tag:0x00007f7397bc3fb0> #<Tag:0x00007f7397bc3c90> #<Tag:0x00007f7397bc3b28>

I have gotten my ShellyDimmer2 working with HA via MQTT following some posts I found in these forums.

Now I would like to try and reach the final goal of these dimmers.

I have an automation set to turn the lights on, brightness at 15% at sunset (Porch lights). I would like to also have the wall switch control them so if the wall switch turns on, the lights come up to 100%, and when the switch is turned off, the lights will go back to 15% until midnight. After midnight, the lights will just be off (unless the wall switch is turned on of course).

The idea being that i can have general aesthetic lighting unless we need to have the lights on for a visitor or specific reason.

I can automate the sunset/midnight parts easily. but how do I monitor the shelly’s switch input to set the brightness higher when true, and then check time of day to determine whether to return to the dimmer setting, or completely off when the switch input goes false?

via MQTT Explorer i can see
“shellies/ShellyDimmer_Porch1/input” topic reporting a “0=0” and a “1=0” which I believe is the SW1/SW2 terminals on the device. when i connect SW1 to L1, I see “0=1”. So I just need some help building the logic to asses that against the time of day.

Thanks in advance for any help!

OK Through some trial and error, i managed to figure it out… It feels like there is probably a much more elegant solution, so I am open to suggestions. As it is, the “Porch SW OFF (Nighttime)” automation gets called every time the shelly updates it’s status via MQTT (which is about every 30 seconds) so the log is a lot of repeat entries…

BUT it does seem to be working… Or so I hope. I played with set times before converting to sunrise/sunset triggers/conditions.

Please feel free to offer suggestions to improve what i’ve got here.

Automations.yaml

- id: '1605998579299'
  alias: Porch SW OFF (Nighttime)
  description: Forces lights to stay on at 15% and switch in OFF position. Only active
    at night time.
  trigger:
  - platform: mqtt
    topic: shellies/ShellyDimmer_Porch1/input/0
    payload: '0'
  condition:
    condition: state  # from sunset until sunrise
    entity_id: sun.sun
    state: 'below_horizon'
  action:
  - type: turn_on
    device_id: 8fc247dd2bb411eb98b5eff152b77ea4
    entity_id: light.shelly2dimmer1_light_0
    domain: light
    brightness_pct: 15
  mode: single
- id: '1605998667378'
  alias: Porch SW ON
  description: Force lights to 100% brightness when switch is ON
  trigger:
  - platform: mqtt
    topic: shellies/ShellyDimmer_Porch1/input/0
    payload: '1'
  condition: []
  action:
  - type: turn_on
    device_id: 8fc247dd2bb411eb98b5eff152b77ea4
    entity_id: light.shelly2dimmer1_light_0
    domain: light
    brightness_pct: 100
  mode: single
- id: '1605998667379'
  alias: Porch Lights Sunrise
  description: Turn Porch Lights off at sunrise
  trigger:
  - platform: sun
    event: sunrise
  condition: []
  action:
  - type: turn_off
    device_id: 8fc247dd2bb411eb98b5eff152b77ea4
    entity_id: light.shelly2dimmer1_light_0
    brightness_pct: 100
    domain: light
  mode: single

EDIT: Code originally posted did not work, updated to my current running version which i do have working, although not quite exactly as I’d like…