Simple Automation problems

So would it go:

- alias: 'Lights On'
  initial_state: on
  trigger:
    platform: state
    entity_id: binary_sensor.vision_zp3111_multisensor_4in1_sensor
    from: 'off'
    to: 'on'
  condition:
    condition: and
    conditions:
      - condition: sun
        after: sunset
      - condition:  
        before: sunrise
      - condition: time
        after: '18:00:00'
        before: '22:00:00'
  action:
    - service: light.turn_on
      data:
        entity_id: light.level_2
        brightness_pct: 100

And does the rest of it look okay? Because for whatever reason this isn’t working.

Initial_state: ‘on’ - with quotes.

You still haven’t told us whether they actually are switched on?

Also, I don’t know where you are in the world, but I’m guessing that it’s never before sunrise AND between 6-10pm in the same day.

My guess is that the conditions you want are:

condition:
  condition: or 
  conditions:
    - condition:  
      before: sunrise
    - condition: and
      conditions:
        - condition: sun
          after: sunset
        - condition: time
          after: '18:00:00'
          before: '22:00:00'

@anon43302295 thanks so much for your help. I’m obviously still getting the hang of how all the syntax works off of one another. This is what I currently have

- alias: 'Lights Off'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: binary_sensor.vision_zp3111_multisensor_4in1_sensor
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 30
  action:
    service: lights.turn_off
    entity_id: light.level_2
  
- alias: 'Lights On'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: binary_sensor.vision_zp3111_multisensor_4in1_sensor
    from: 'off'
    to: 'on'
  condition:
    condition: or 
    conditions:
      - condition:  
        before: sunrise
      - condition: and
        conditions:
          - condition: sun
            after: sunset
          - condition: time
            after: '18:00:00'
            before: '22:00:00'
  action:
    - service: light.turn_on
      data:
        entity_id: light.level_2
        brightness_pct: 100

- alias: 'Lights On Nighttime'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: binary_sensor.vision_zp3111_multisensor_4in1_sensor
    from: 'off'
    to: 'on'
  condition:
    condition: or 
    conditions:
      - condition:  
        before: sunrise
      - condition: and
        conditions:
          - condition: sun
            after: sunset
          - condition: time
            after: '18:00:00'
            before: '22:00:00'
  action:
    - service: light.turn_on
      data:
        entity_id: light.level_2
        brightness_pct: 25 

The goal is to get the lights to do those things only if the sun is down (e.g. I don’t want the lights going on on motion at 6pm if the sun is still up, like in the summer, but do want them going on at 6pm if the sun is down in the winter).

As I have it currently it says “invalid config” and i’m searching through it for the reason why. Also, if I can somehow buy you a beer let me know. I’ll send ya the money or something :wink:

In the first one, your service is lights.turn_off - should be light (no S).

What’s the actual error message?

It’s long, but this is the first part of it:

Testing configuration at /config
Failed config
automation:
- Invalid config for [automation]: extra keys not allowed @ data[‘condition’][0][‘conditions’][0][‘before’]. Got None
not a valid value for dictionary value @ data[‘condition’][0][‘conditions’][0][‘condition’]. Got None
required key not provided @ data[‘condition’][0][‘conditions’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 98). Please check the docs at Automation - Home Assistant
- binary_sensor: [source /config/configuration.yaml:86]
- platform: template
sensors: [source /config/configuration.yaml:88]
hallway_motion: [source /config/configuration.yaml:89]
friendly_name: Hallway Motion
value_template: {%- if is_state(‘sensor.vision_zp3111_multisensor_4in1_burglar’, ‘8’) -%} true {%- else -%} false {%- endif -%}

Which line is 98?

Also your second and third automation have the same trigger, and the same conditions, with conflicting actions. Based on their titles that should be one automation with a data_template to set the brightness. What hours do you want the lower brightness between?

The lower brightness should be between 10pm and 7am.

As for line 98…I don’t have a line 98 in my automations. In my configuration, its group: !include groups.yaml. So I’m not sure…

OK, you have an automation saved somewhere else that’s causing the error by the sound of that, maybe accidentally pasted something in your groups file?

Standby a sec and I’ll redo your lights on automation…

OK, get rid of the ‘lights on night’ automation completely, and replace the other one with…

- alias: 'Lights On'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: binary_sensor.vision_zp3111_multisensor_4in1_sensor
    to: 'on'
  condition:
    condition: or 
    conditions:
      - condition: sun 
        before: sunrise
      - condition: and
        conditions:
          - condition: sun
            after: sunset
          - condition: time
            after: '18:00:00'
            before: '22:00:00'
  action:
    - service: light.turn_on
      data_template:
        entity_id: light.level_2
        brightness_pct: >
          {% if (now().hour >= 22) or (now().hour <7) %} 25
          {% else %} 100 {% endif %}
- alias: 'Lights Off'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: binary_sensor.vision_zp3111_multisensor_4in1_sensor
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 30
  action:
    service: light.turn_off
    entity_id: light.level_2
  
- alias: 'Lights On'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: binary_sensor.vision_zp3111_multisensor_4in1_sensor
    to: 'on'
  condition:
    condition: or 
    conditions:
      - condition: sun 
        before: sunrise
      - condition: and
        conditions:
          - condition: sun
            after: sunset
          - condition: time
            after: '18:00:00'
            before: '22:00:00'
  action:
    - service: light.turn_on
      data_template:
        entity_id: light.level_2
        brightness_pct: >
          {% if (now().hour >= 22) or (now().hour <=7) %} 25
          {% else %} 100 {% endif %}

This is what I have now. It passes the configuration test but the automation doesn’t seem to work when I walk past the motion detector. Any further thoughts?

Have you restarted HA?

What time is it there?

I did restart it. And it is currently 10:00pm here.

Could it have to do with that I have a sensor template active? I’m not using it as my entity ID obviously, but I do have it in my config.yaml still.

Remove the line before: '22:00:00' completely.

Also, I’m really sorry, but I got confused earlier, it should be initial_state: on (without quotes).

Template sensor shouldn’t be affecting this.

Please, do not feel like you need to apologize. This has all been extremely helpful for me to learn how these things are worded correctly. I’m restarting it now, will let you know what happens.

Fingers crossed :sunglasses:

Nothing. When I trigger both automations manually via the Front End they work appropriately, but the motion sensor does not activate them.

- alias: 'Lights Off'
  initial_state: on
  trigger:
    platform: state
    entity_id: binary_sensor.vision_zp3111_multisensor_4in1_sensor
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 30
  action:
    service: light.turn_off
    entity_id: light.level_2
  
- alias: 'Lights On'
  initial_state: on
  trigger:
    platform: state
    entity_id: binary_sensor.vision_zp3111_multisensor_4in1_sensor
    to: 'on'
  condition:
    condition: or 
    conditions:
      - condition: sun 
        before: sunrise
      - condition: and
        conditions:
          - condition: sun
            after: sunset
          - condition: time
            after: '18:00:00'
  action:
    - service: light.turn_on
      data_template:
        entity_id: light.level_2
        brightness_pct: >
          {% if (now().hour >= 22) or (now().hour <=7) %} 25
          {% else %} 100 {% endif %}

I take it your sensor is showing as on in the states panel when you walk past it?

Yep, just double-checked.

And you’ve definitely copied the entity_id for it correctly?

And your time zone is correct? (so in your states panel sun is showing below horizon?)