Shelly Dimmer SW1 input AND Time of Day controls Automations

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…

Hi Xplode, interested to hear if you have got a solution. I also would like to set a certain schedule depending on the time of the day what the dim level is when the wall switch is used to turn on the lights.

I did and the solution i found is right above your post.

I did not stick with this solution however, as I’ve now added extra triggers from my Surveillance cameras when they detect motion. Also, HA now added the “choose” function in the automations for the actions, so it’s a lot easier to make the complex automation under a single automation, instead of 3 or 4.

I haven’t updated to the “choose” thing yet, as I updated my Surveillance system and it’s now on the fritz, triggering motion constantly. :roll_eyes: But I will get back to it. If I remember, I’ll post it up here.