Lightsensor and time

I cant get this right, i want my lightsensor to turn on the lights after 18:00 but before 20:00 if not the sensor activates i vant my lights to turn on at 20:00

- alias: Utomhus_on
  hide_entity: false
    - platform: state
      entity_id: binary_sensor.ljusensor
      to: 'on'
    - platform: time
      at: '20:00:00'
    - condition: time
      after: '18:00:00'
      before: '19:00:00'
    - condition: state
      entity_id: binary_sensor.ljusensor
      state: 'on'
    service: scene.turn_on
    entity_id: scene.utomhus_on

you need to format your code correctly per the instructions at the top of the page. Syntax is important.

Yes, sorry for that i had some computer issues…despite from the format does it look like it would do that i want?

I don’t know. I can’t see the syntax… :wink:

But just as a guess from what I can see you will only get the lights to turn on between 1800 & 1900 and only if your light sensor changes to on during that hour.

Right now your trigger is either the light sensor OR time being at 2000.

But your conditions require the light sensor to be on AND the time between 1800 & 1900.

So for your first trigger, if your light sensor turns on before 1800 or after 1900 then the lights won’t turn on. And for your second trigger, since 2000 isn’t between the hours of 1800 and 1900 then that won’t turn the lights on at 2000 either.

Maybe start out with two automations:

  1. trigger the lights on with the light sensor turning on and condition set to after 1800 and before 2000.

  2. turn the lights on with a time trigger at 2000 with no conditions.