#How to use toggles and helps for conditions in a script?
1 messages · Page 1 of 1 (latest)
You want to test for the Entity ...the states are off or on as seen here. In your case, it would be something like
"entity_id: input_boolean.maintain_light_state"
That image is pretty hard to read. Could you either do a screen capture, or click the 3 dots at the top right, select edit in YAML and copy the text for posting here?
What happens if you go to the search on a dashboard and search for "maintain_light_state"?
It looks like you're missing the domain for "maintain_light_state". It should be an input_boolean, or a binary_sensor, or... something that looks like "foo.maintain_light_state"
Hang on i think i explained this poorly...
Theres 2 things at play here, a script and an automation. My goal is to always invoke this script for my lighting needs, so this script accepts 3 inputs, a light group, a maintain brightness toggle, and a update light state. Ignore the update lights state one cause its used for something different: Here is what this script accepts: and what it does with them, how come green works but red doesnt.
To be clear im passing the entity in.
I am pretty sure it's not able to evaluate your template to get maintain_light_state
Is it being set by your script? If so, I think you're gonna need that response_variable and you'll need to put it in a response variable from your script.
Seeing your YAML would be helpful. The screenshots don't have all the context needed.
sequence:
- if:
- condition: state
entity_id: input_boolean.homealone
state: "on"
then: - if:
- condition: state
entity_id: "{{ maintain_light_state }}"
state: "on" - condition: template
value_template: Maintain Light State
then: - action: light.turn_on
metadata: {}
data:
transition: |
{{ states('input_number.light_transition_speed') | int }}
target:
entity_id: "{{ light_group }}"
enabled: true
else: - if:
- condition: template
value_template: "{{ update_light_temp }}"
then: - action: light.turn_on
metadata: {}
data:
kelvin: |
{{ states('input_number.lighttemp') | int }}
transition: |
{{ states('input_number.light_transition_speed') | int }}
target:
entity_id: "{{ light_group }}"
enabled: true
else: - action: light.turn_on
metadata: {}
data:
brightness_pct: 100
transition: |
{{ states('input_number.light_transition_speed') | int }}
target:
entity_id: "{{ light_group }}"
enabled: true - action: light.turn_on
metadata: {}
data:
kelvin: |
{{ states('input_number.lighttemp') | int }}
target:
entity_id: "{{ light_group }}"
enabled: true
alias: SC MasterSmartLightTemp
mode: single
icon: mdi:lightbulb
fields:
light_group:
selector:
entity:
multiple: true
name: Light Group
required: true
update_light_temp:
selector:
boolean: {}
name: Update Light Temp
description:
required: true
maintain_light_state:
selector:
entity: {}
name: Maintain Light State
description: ""
- condition: template
- condition: state
- condition: state
So like the red works...
Passing the light group entity works just as expected
Here is the automation that is using it:
alias: Office Lighting
description: ""
triggers:
- type: opened
device_id: 2eb37ec055807cf2e295b07645db914b
entity_id: fd613a9f8949510164a6a385c682c726
domain: binary_sensor
trigger: device
id: On Maintain Bright - trigger: state
entity_id:- input_boolean.tg_office_lights
from: null
to: null
id: On Full Bright
- input_boolean.tg_office_lights
- type: not_opened
device_id: 2eb37ec055807cf2e295b07645db914b
entity_id: fd613a9f8949510164a6a385c682c726
domain: binary_sensor
trigger: device
id: "Off"
conditions: []
actions: - choose:
- conditions:
- condition: trigger
id:- On Full Bright
sequence:
- On Full Bright
- action: script.sc_mastersmartlighttemp
metadata: {}
data:
light_group:
- light.lg_office
maintain_light_state: false
update_light_temp: false
- condition: trigger
- conditions:
- condition: trigger
id:- On Maintain Bright
sequence:
- On Maintain Bright
- action: script.sc_mastersmartlighttemp
metadata: {}
data:
maintain_light_state: input_boolean.tg_maintain_light_state_office
light_group:
- light.li_bathvanr1
update_light_temp: false
- condition: trigger
- conditions:
- condition: trigger
id:- "Off"
sequence:
- "Off"
- action: light.turn_off
metadata: {}
data: {}
target:
entity_id: light.lg_office
mode: single
- condition: trigger
- conditions:
This is what it looks like when im calling the script. So im saying call this script with this light group and this toggle to see if when you call it you should maintain the brightness (Ik it says Bath light and office toggle just ignore that haha the idea is there)
So when you call this script it should accept that light group, which works perfectly fine. but i just want the script to conditionally execute based on the toggle state of that toggle, so i passed it as a toggle
This is a flow chart for an example of what im trying to do.
Just to understand what the end goal here is I want to be able to say to alexa like "Lock living room lights" and it would turn that toggle on so then when i walk away and the lights shut off when i walk back in there, or if it somehow got retriggered by motion the lights would come back on how they were last time, and not go fully bright again. The reason for this is because if i press the switch i alway want the lights to go fully bright, and im trying to make this so i can maintain one single lighting script for everything, seeing you can see the whole yaml now the reason for the "Update Light Temp" one is because I have a seperate automation that checks the state of every light when the sun state changes. if the light is on when the sun sets or rises it will update their kelvin value, so that automation will use that Update Light temp boolean but its not relevant to this one.
Here is me hard coding the toggle inside the script (which i dont want to do)
Where when i try to replace that hardcoded entity ID with the what im passing it doesnt work.
To be clear this is the exact same way i am accepting the LG field:
What happens if you do this?
sequence:
- if:
- condition: state
entity_id: input_boolean.homealone
state: "on"
then: - if:
- condition: template
value_template: "{{ maintain_light_state }}"
- condition: template
- condition: state
I'm not sure that will work, but hopefully it gives different enough behavior/errors to help you get things fixed.
It seems like you're really focused on the light group working and the input boolean not working even though they are being handled the same. They are different types and are handled differently, so... Gonna have to try some other things with the bool
Actually, what I proposed looks just like the stuff I was having trouble with myself (which I got working, btw...)
Look at the code snippet I posted here
#1329905726080155739 message
No it still didnt like the
condition: template
value_template: "{{ maintain_light_state }}"
It says your entity_id is undefined in this one.
You really need to post your error messages, not just "it doesn't work"
What happens when you go to your dashboard and click on the magnifying glass and put in "maintain_light_state"? Can you find it? Does it have a domain?
It’s not not somthing that would be in the dashboard, it’s a field for the script… just like that code shows light_group, it’s not defined until I call the script and pass it the entity.
To be clear hard coding that toggel works, when I try to pass that toggle from the automation it doesn
Now I understand what you're trying to do and why it has you so baffled...
Sorry, I don't have any experience with passing variables to scripts. All I can come up with is that the one that works is specified with required: True, and the one that isn't working isn't specified that way.