Simple but bad light automation

I’ve checked the forum and the interwebs looking for an example to do this… yeah I know it’s simple except it isn’t working LOL

- alias: 17 - Turn on light if dark
  id: 17 - Dark Lights
  initial_state: true
  trigger:
    platform: state
    entity_id: light.wled_fun
  action:    
    service_template: >
      {% if trigger.entity_id == 'light.wled_fun' %}
      {% if is_state('light.wled_fun', 'off') and state_attr('binary_sensor.front_door_motion_occupancy', 'illuminance') < 50 %}      
        input_boolean.turn_on
      {%else%}
        input_boolean.turn_off
      {%endif%}
      {%endif%}
    target:
      entity_id: light.wled_fun

So apparently my automation isn’t speaking the correct language… what did I miss?

in my config

input_boolean:
   turn_on:
    name: turn on
  turn_off:
    name: turn off

Thank you!

You probably should tinker around with the template here: /developer-tools/template

What does the full ERROR? Click the red letters. :wink:

Overall the first to lines in the template look weird to me.

It’s an automation. I’ve used those since I started and they are numbered easier for me to find :slight_smile:

Logger: homeassistant.components.automation.17_turn_on_light_if_dark
Source: components/automation/__init__.py:525
Integration: Automation (documentation, issues)
First occurred: 1:12:08 PM (2 occurrences)
Last logged: 1:28:13 PM

Error while executing automation automation.17_turn_on_light_if_dark: Template rendered invalid service:

and

Logger: homeassistant.components.automation.17_turn_on_light_if_dark
Source: helpers/script.py:1718
Integration: Automation (documentation, issues)
First occurred: 1:12:08 PM (2 occurrences)
Last logged: 1:28:13 PM

17 - Turn on light if dark: Error executing script. Error for call_service at pos 1: Template rendered invalid service:

Unless I’m midreading I’m thinking the issue is here →

action:    
    service_template: >
      {% if trigger.entity_id == 'light.wled_fun' %}
      {% if is_state('light.wled_fun', 'off') and state_attr('binary_sensor.front_door_motion_occupancy', 'illuminance') < 50 %}      
        input_boolean.turn_on
      {%else%}
        input_boolean.turn_off
      {%endif%}
      {%endif%}
    target:
      entity_id: light.wled_fun

I’m totally fine with your naming and yes, I was talking about the template’s first two lines.

After reading it I just can’t my head around what you’re trying in general. :wink:

The trigger should be the light itself? But what attribute and what should be the trigger? Shouldn’t be the trigger teh binary sensor?

I will relook at it… at the moment I discovered a couple errors in the config that can potentially be giving me some issues that may or may not affect what’s going on… have to fix those first. :slight_smile:

1 Like

But I got you right? If the illuminance of you light sensor at the front is below 50 the wled fun should be on and if it’s lighter at the door the wled should be off?

Good look tidying stuff up!

1 Like

Yes!! You got it! The config has so many conflicting issues that I have to fix them… WOW I guess I better pay better attention to things…

It changed my theme… amongst other things… it was trashed LOL Since I took today off [glad I did due to weather] I just found lots of errors… most important to fix those first…

I had input boolean in my config and a seperate directory for that… so one overrides the other and explains why some of the other things I tried to do [not this one] didn’t work…

Well okay that was easier then I thought NOW everything is back to ‘normal’ and I can look at this again.

The easy way for the short but early happiness: Turn on light, switch, scene, script or group based on motion and illuminance (+ more conditions)

Why yes much easier…

Was/am trying to learn new things… so I gave it a shot… it didn’t go well LOL I can use that but get no benefit from not learning how to do this…

Was my attempt at using a service_template… as I’m reading through my attempt I’m seeing the mess there… :slight_smile:

OHHHHHHHH seeeeee learned something new today… working :slight_smile: [I have it set to 100 just for testing]

- alias: 17 - Turn on light if dark
  id: 17 - Dark Lights
  initial_state: true
  trigger:
    platform: state
    entity_id: light.wled_fun
  action:    
    service_template: >      
      {% if state_attr('binary_sensor.front_door_motion_occupancy', 'illuminance') < 100 %}      
        homeassistant.turn_on
      {%else%}
        homeassistant.turn_off
      {%endif%}
    target:
      entity_id: light.wled_fun

As a teacher by education and business owner [with too much time on my hands today, that dangerous] I like to know how things ‘work’… I look at it like this… if it breaks and I built it then
I know where to go to fix it. If I just plug things in then I’m waiting on someone else to fix it and
we are all busy :slight_smile: I do REALLY appreciate all your input!!!

I’ve written modules for other projects →

With my weather module being the most complex thing I ever did… mulitple providers and ‘looks’ and with help translated for 11 different languages…
So it’s in my nature to tear things apart and put them back together LOL I’m sure many are sick of my questions but it’s how I learn best.

1 Like

That was what I was intending:
Look at the blueprint, go to yaml and learn about the template.

Like reading the manual of a x, throwing the manual in the bin and build a x+y out of it.

Happy to help you a little!

1 Like

You know what… you are RIGHT!!! I will go do that!!! Thank you VERY much!