I’ve been searching the threads to find an answer, but I can’t seem to find my mistake. I’m using a Sonoff basic with Tasmota installed and integrated via mqtt. I can see the sonoff via the mosquitto broker add-on log. I also can see that the sonoff has signed on through the sonoff console. I have a card on the home asssistant front end where I can toggle the sonoff on and off.
Here’s my problem: I’m trying to set up an automation to turn some lights on at sunset and off at sunrise, but I’m making a mistake somewhere, but I can’t seem to find it. When I click on Check Config, I get no errors. Here is my automation:
sonoff is named ‘lights’
automation:
- alias: 'Sconce Lights on 45 minutes before sunset'
initial_state: 'off'
trigger:
- platform: sun
event: sunset
offset: '-0:45:00'
action:
service: switch.turn_on
entity_id: switch.lights
- alias: 'Sconce Lights off 45 minutes after sunrise'
initial_state: 'on'
trigger:
- platform: sun
event: sunrise
offset: '+00:45:00'
action:
service: switch.turn_off
entity_id: switch.lights
Sorry I’ve been silent. I appreciate all the feedback. I’ve been trying different scenarios, but still no cigar…
My latest attempt looks like this. I’ve only included the first automation as the other two have an identical format.
I’m really struggling to understand the issue. The automation does not fire. I don’t see any errors in the log, nor do I see any record of any attempt in the logs. I’m quite befuddled with this.
I added an automation id, as recommended in another forum post, but no change.
I changed the service being called to Mqtt.publish, in case I was trying to use the wrong service in my previous attempts, no change.
Per recommendation from Akriss, I changed the initial_state to ‘true’, then “true”, then true, but still no change.
I also added data: thinking that maybe I was missing a simple thing—this was recommended in a similar post elsewhere. Still no change.
Any inspiration??
- id: 123456
alias: 'Sconce Lights on 45 minutes before sunset'
initial_state: 'true'
trigger:
- platform: sun
event: sunset
action:
data:
service: mqtt.publish
topic: 'cmnd/sonoff/POWER'
payload: OFF
entity_id: switch.lights
@Enginerd - the issue is you are publishing to the wrong topic. State is upper case, command is lower case. Also, wouldn’t you be better off defining the light as a light first, then turn it on with the automation? See example below:
I finally figured it out. Stupid mistake, but I want to post so any other newbies like me can learn from my mistake. When entering the device_id, I did not have quotes around the name of the device I’m using to call the service. Pretty simple, but it makes the difference between something “working” or not.
Thanks everyone for your comments and suggestions. Several good examples to use. Thanks again.