Good afternoon all can anyone help me with the set up of sun after sunset/ before sunrise on a binary sensor(PIR) with an existing condition.
- alias: Light On
hide_entity: true
initial_state: 'on'
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: 'on'
condition:
- condition: state
entity_id: switch.Light
state: 'off'
action:
- service: switch.turn_on
data:
entity_id: switch.Light
i have tried a few different things but unsuccessful any help would be massively appreciated.
Can you please format the code? See help from the blue banner on top of the forum.
Also, I think entity IDs can’t have upper case letters. You can see what home assistant is using from the “<>” menu.
is that any better?
- alias: Light On
hide_entity: true
initial_state: 'on'
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: 'on'
condition:
- condition: sun
after: sunset
before: sunrise
action:
- service: switch.turn_on
data:
entity_id: switch.Light
- alias: Light On
hide_entity: true
initial_state: 'on'
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: 'on'
condition:
- condition: state
entity_id: switch.Light
state: 'off'
action:
- service: switch.turn_on
data:
entity_id: switch.Light
Have i done something wrong??
No,
I withdrew my post because you got it right in the edit to your original post, and now your second post look fine too.
Give me a sec to look at your actual code now.
Ah thanks apologies if sounding mega stupid
Ok, so the object is to have the PIR sensor trigger a light to turn on when it’s after sunset, but before sunrise?
- alias: Light On
hide_entity: true
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: 'on'
condition: and
conditions:
- condition: sun
after: sunset
before: sunrise
- condition: state
entity_id: switch.Light
state: 'off'
action:
- service: switch.turn_on
data:
entity_id: switch.Light
That should work I believe, however there’s really no need to check if the light is already off before turning it on. If it’s already on and you tell it to turn on, no harm no foul.
yeah have a light in a hallway i would like to switch via a pir but not in the day when no need for the light to be on
Then you can pretty much eliminate checking if the light is on or off, and just check the state of the sun sensor:
- alias: Light On
hide_entity: true
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: 'on'
condition: and
conditions:
- condition: sun
after: sunset
before: sunrise
action:
- service: switch.turn_on
data:
entity_id: switch.Light
But the entity still can’t have capital letters in it.
i copied and pasted this but seem to get a config error now.
Configuration invalidCHECK CONFIG
Invalid config for [automation]: expected a dictionary @ data[‘condition’][0]. Got None extra keys not allowed @ data[‘conditions’]. Got None. (See /config/configuration.yaml, line 124). Please check the docs at https://home-assistant.io/components/automation/
Ah yes, try this then:
- alias: light on
hide_entity: true
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: 'on'
condition: or
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
action:
- service: switch.turn_on
data:
entity_id: switch.light
syntax is wrong, should be this:
- alias: light on
hide_entity: true
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: 'on'
condition:
- condition: or
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
action:
- service: switch.turn_on
data:
entity_id: switch.light
Good catch.
Cheers all just putting it to the test now