How to switch a MQTT switch on at a certain time

Hi guys

I’m very new here and need some help.
I just can’t seem to figure out the automation of this.

I want to say turn my light on at 22:00 every day and then off again at 05:00 and I can’t get the code right in the configuration file

Here is my switch info:

switch:
  - platform: mqtt
    name: "Living Room"
    state_topic: "home/sonoff/living_room/1/stat"
    command_topic: "home/sonoff/living_room/1"
    qos: 0
    payload_on: "on"
    payload_off: "off"
    optimistic: false
    retain: true

You can try something like this:

automation:
- alias: Turn On Living Room light at 22:00
  trigger:
    platform: time
      hours: 22
      minutes: 00
      seconds: 00
  action:
    service: light.turn_on
    entity_id: light.living_room

To turn off, just change service: light.turn_on to light.turn_off

1 Like

I had to change it slightly to to avoid errors:

automation:
- alias: Turn On Living Room light at 22:00
  trigger:
    platform: time
    after: '22:00:00'
  action:
    service: light.turn_on
    entity_id: light.living_room

But now I see in cmd that “unable to find service light.turn_on”
I also tried light,payload_on, but that didn’t work either.

I’m very proud of myself because I figured it out :slight_smile:

automation:
- alias: Turn On Living Room light at 22:00
  trigger:
    platform: time
    after: '11:51:00'
  action:
    service: switch.turn_on
    entity_id: switch.living_room
3 Likes