Sonoff/mqtt Automation Issues

Hello folks; I have configured and added several sonoff switches for my lights and just can’t get the automation’s to work.

My switches are configured as below and work fine via HA UI interface.

- platform: mqtt
  name: "Sonoff Switch 1"
  state_topic: "stat/sonoff_1/POWER"
  command_topic: "cmnd/sonoff_1/POWER"
  availability_topic: "tele/sonoff_1/LWT"
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_unavailable: "Offline"
  state_on: "ON"
  state_off: "OFF"
  optimistic: false
  qos: 1
  retain: true
- platform: mqtt
  name: "Sonoff Switch 2"
  state_topic: "stat/sonoff_2_th/POWER"
  command_topic: "cmnd/sonoff_2_th/POWER"
  availability_topic: "tele/sonoff_2_th/LWT"
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_unavailable: "Offline"
  state_on: "ON"
  state_off: "OFF"
  optimistic: false
  qos: 1
  retain: true

My automation tests have not worked … and there are no errors in the logs; I tried quoting the time and separating the entities as separate service calls

 ###########  XMas Lights On
- id: xmas_lights_on_morning
  alias: Turn Xmas Lights On
#  initial_state: 'off'
  trigger:
  - platform: sun
    event: sunrise
    offset: -01:15:00
  action:
  - service: switch.turn_on
    entity_id: switch.sonoff_switch_2, switch.sonoff_switch_3
########## XMas Lights off in the Morning
- id: xmas_lights_off_morning
  alias: Turn Xmas Lights Off in the Morning
#  initial_state: 'off'
  trigger:
  - platform: time
    at: 07:45:00
  action:
  - service: switch.turn_off
    entity_id: switch.sonoff_switch_2, switch.sonoff_switch_3

I would appreciate some extra eyes to help point out my errors if any.

Thanks

Your syntax is not correct, under entity_id they need to be listed.
this is how I have mine:  
    - alias: 'Turn On Lamps 20 min Before Sunset'
        trigger:
          platform: sun
          event: sunset 
          offset: "-00:20:00"
        action:
          service: homeassistant.turn_on
          entity_id: 
            - light.living_room_lamp_1
            - light.living_room_lamp_2
            - light.hue_white_lamp_1
            - switch.sues_lamp
1 Like

Thanks @Bluey - I also see that your service is homeassistant.turn_on rather than switch.turn_on.

I will try this out today. This is the best forum that I have know !!!

Reason I have used “home assistant.turn_on” and not “switch.turn_on” is because my list of entities contains both a switch and lights so if I had used “switch.turn_on” only the switch entity would work :slight_smile:

2 Likes

Now there’s a good tip!
Have my like kind sir!

Tips and tricks like @Bluey 's post make this forum - helpful and inspirational !!

After a few (many) days I got my OwnTracks implementation working and my next project is proximity sensors to make the presence detection - more robust.

you can find more automation examples in the link aabove.

@TerroBladeZ Thanks for the detailed listing - I will definitely take some tips from the settings but I’m afraid to ask… Valentine’s day Lighting - seriously does “deeppink” work?

lol I dont know. I check this GitHub page when I need automation ideas. He has more then 300 automation in his HA.