Turn on scene when front door is opened

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

Can anyone see any glaring errors there at all?

It can’t be before 45 minutes before sunset AND after sunset at the same time.

I have gone into the yaml file to see what that has added, and this is it below:

  alias: Front Door
  description: ''
  trigger:
  - device_id: 8ef08062162a45a49bfb4144a0b380aa
    domain: binary_sensor
    entity_id: binary_sensor.front_door_contact
    for:
      hours: 0
      minutes: 0
      seconds: 1
    platform: device
    type: opened
  condition:
  - after: sunset
    before: sunset
    before_offset: -00:45:00
    condition: sun
  action:
  - scene: scene.front_door

Not sure if that helps at all! I’m guessing it’s something to do with the sunset part? Ideally 45 minutes before sunset and stop after sunrise.

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!

So you only want the action to run if the trigger happens between 45 minutes before sunset and sunrise? If so:

  condition:
  - condition: or
    conditions:
    - condition: sun
      after: sunset
      after_offset: -00:45:00
    - condition: sun
      before: sunrise

Thank you @pnbruckner, will give that a try. Just to double check, the last ‘before’, should that be sunrise rather then sunset?

What do you mean? :wink: (Sorry, fixed it.)

1 Like

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.

1 Like

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.

shouldn’t action be

service: scene.turn_on
entity_id: scene.front_door

edit
yes it should: https://www.home-assistant.io/integrations/scene/

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
1 Like

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.

- id: '1575929929701'
  name: Front Door New
  entities:
    light.front_room_wall:
      brightness: 110
      color_temp: 241
      hs_color:
      - 219.6
      - 2
      rgb_color:
      - 249
      - 251
      - 255
      state: 'on'
      xy_color:
      - 0.318
      - 0.325
    light.tv_back_light_front_room:
      brightness: 128
      color_temp: 355
      hs_color:
      - 43.2
      - 48
      rgb_color:
      - 255
      - 220
      - 132
      state: 'on'
      xy_color:
      - 0.436
      - 0.415

Thank you, just tried

action:
    service: scene.turn_on
    entity_id: scene.front_door

but still no joy with that scene being activated. In the post above, I think my scene is knackered somewhere!

I would think so indeed :wink:

write the colors like this:

- id: '1575929929701'
  name: Front Door New
  entities:
    light.front_room_wall:
      brightness: 110
      color_temp: 241
      hs_color: [219.6,2]
      rgb_color: [249,251,255]
      state: 'on'
      xy_color: [0.318, 0.325]
    light.tv_back_light_front_room:
      brightness: 128
      color_temp: 355
      hs_color: [43.2,48]
      rgb_color: [255,220,132]
      state: 'on'
      xy_color: [0.436,0.415]

but of these, choose 1 only, you now have rgb, hs and xy color set, which would work

also is there really a ‘light.tv_back_light_front_room’ or is this a type, and should these be 2 lights: ‘light.tv_back’ and ‘light.front_room’

No. It can be, but it’s also ok the way it was. See activate a scene.

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…

40

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.

@pnbruckner and @Mariusthvdb , thank you both so much for your help.
I’ve solved it!

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 .

Thank you both again

1 Like