Hi,
Slowly trying to move my automations over from SmartThings, but i’m struggling to see where i’ve gone wrong with this one.
I’ve got a scene set up that turns on two lights in the front room. When I tes that, it works fine. I want to create an automation that activates this scene when the front door is open between sunset and sunrise.
This is what i’ve done, but can’t get it to work!
Trigger type: Device
Device: Front Door
Trigger: Front Door contact opened
Duration: 00:00:00
Condition type: Sun
Before: Sunset
Before offset: -00:45:00
After: Sunset
After offset: (Optional)
Action Type: Activate Scene
Entity: scene.front_door
Thanks @pnbruckner
Doh! I thought you had to choose one from each section, as was highlighted! Just gone and checked and you can de-select! Will give that a try!
Thanks, just wanted to check! I’ll give that a test when I go upto bed. Don’t want to annoy the other half that’s sleeping by keep going up the stairs to open the front door! Will let you know how I get on!
Well, if you didn’t use that newfangled device type of trigger you could easily test it without actually opening the door. Change the trigger to:
trigger:
- platform: state
entity_id: binary_sensor.front_door_contact
to: 'on'
Then go to the STATES tab of the Developer Tools page, click on binary_sensor.front_door_contact, then at the top of the page change off to on (where it says State), then click SET STATE. That will (temporarily) change the state of the binary sensor to on, which will trigger the automation.
Thank you. Tried that but no joy. It’s showing the front door as being open, however none of the lights came on. Something obvious that i’ve missed here?
alias: Front Door
description: ''
trigger:
- entity_id: binary_sensor.front_door_contact
platform: state
to: 'on'
condition:
- condition: or
conditions:
- after: sunset
after_offset: -00:45:00
condition: sun
- before: sunrise
condition: sun
action:
- scene: scene.front_door
Did you restart HA after changing the YAML file? But first, did you do a config check? Maybe it’s just a cut/paste error, but alias needs to be indented the same as description, trigger, condition & action.
alias: Front Door
description: ''
trigger:
platform: state
entity_id: binary_sensor.front_door_contact
to: 'on'
condition:
condition: or
conditions:
- condition: sun
after: sunset
after_offset: -00:45:00
- condition: sun
before: sunrise
action:
service: scene.turn_on
entity_id: scene: scene.front_door
Yeah, did a config check and all came back well. I also restarted my HA but no joy.
Maybe I think it has something to do with the scene. These seem to be ones imported in from ST. If I click on Configuration>> Scenes , I can click on the scene and it works. However the edit button is greyed out. If I try doing it via dev tools using:
Entity: scene.front_door
State: scening
or
Entity: scene.front_door
State: on
Neither turns the lights on. I’ve since gone into Scenes and tried to create a new one, and although it shows up in the scenes.yaml , it doesn’t display in the scenes tab. I then can’t work out how to get a name of this scene which I can use in to the automation.
You can check if the action part works by clicking the icon to the left of the automation on the STATES tab of the Developer Tools page. That will open its “more info” window. In that window click the TRIGGER button. That will ignore the trigger & conditions and unconditionally run the actions. If the lights still don’t turn on, then yes, it looks like there’s something wrong with the scene.
Well, I’ve never seen that, thanks for showing me. It’s not on the scene integration doc page though, and it’s not in the developer/service page options…
on the script service, all scripts are listed there, since we can call these directly, here, none of the scenes I have are listed.
Id choose the service: scene.turn_on way, at least until the scene would run perfectly…
Apparently it’s not registered as a service, so it wouldn’t show up in the services list, would it? scene is just another type of step you can have in a script, like service, delay, wait_template, etc. At least, that’s what the docs say. I’ve never tried it myself because I don’t use scenes.
It did indeed appear to possibly be a dodgy scene imported across from Smartthings. The second issue was all me, in the config file I didn’t have
scene: !include scenes.yaml`
As soon as I added that and rebooted, the scene showed up under the Scenes tab and also in developer tools. I was then able to add the new scene into the code, and run the test like @pnbruckner said and it worked a treat!
Such a great learning experience! I shall continue tomorrow in moving the rest of my door/light automations over to HA .