Help! First atempt at automation

Hi guy’s, new to the Home Assistant eco system after tarting off with Alexa and app’s to control my home. Decided to take the leap into Home Assistand and trying to get my first automation to work.

Trying to get my Living Room door sensor to switch on my Conservatory lights after dark. Can anyone see any mistake I have made as when I check my dashboard, all show as open but no lights come on.

Light switch is plug through Tuya and door sensor is Zigbee through ConBee 2

image

Any help or advise would be most welcomed.

In the future, please share text instead of pictures of text. The problem is that your condition will never be true because including both before: and after: with the sun platform requires both to be true. That’s impossible, and is mentioned in the docs here. You can either split it into two conditions, or use something like sun.sun elevation or below_horizon/above_horizon. The latter two options are generally superior to sunrise/sunset anyway.

Thanks for the info. went back and changed condition and read the docs you said about.

  • id: ‘1619913199030’
    alias: Conservatory Lights On
    description: Turn on conservatory lights when Living Room door is opened after dark
    and if not on.
    trigger:
    • platform: state
      entity_id: binary_sensor.tz3000_6jeesvrt_ts0203_ias_zone
      from: ‘off’
      to: ‘on’
      condition:
    • condition: state
      entity_id: sun.sun
      state: below_horizon
      action:
    • service: switch.turn_on
      target:
      entity_id: switch.72627180bcddc2926884
      mode: restart

:+1: :+1: All worked first time.
Thanks.

Excellent, glad to hear it.

One last thing on the code sharing: please use the </> button in the toolbar to preserve formatting in your code, which is critical for YAML.

Like this

I don’t think your automation implements the last thing mentioned in the description: and if not on.

When the door is opened and the sun is below_horizon, the automation will always execute switch.turn_on even if the switch is already on.

If you want the automation to work precisely like it describes its operation in its description, simply add a second State Condition that checks if the switch is currently off.

id: '1619913199030'
alias: Conservatory Lights On
description: Turn on conservatory lights when Living Room door is opened after dark and if not on.
trigger:
- platform: state
  entity_id: binary_sensor.tz3000_6jeesvrt_ts0203_ias_zone
  from: 'off'
  to: 'on'
condition:
- condition: state
  entity_id: sun.sun
  state: below_horizon
- condition: state
  entity_id: switch.72627180bcddc2926884
  state: 'off'
action:
- service: switch.turn_on
  target:
    entity_id: switch.72627180bcddc2926884
mode: restart

Thanks for the extra info. I’ll have a look and insert second condition and see how we get on.

Thanks.