it appears in the front end, but does not follow the state of sun.sun
Is this not the purpose of template switches?
What Iâm trying to do is have the grow light on when ever the sun.sun is âabove_horizonâ.
An example: The automation has only one chance of firing, and thatâs when the sensor changes state. If HA had locked up the minute before and required a reboot, then the trigger would expire and the light wonât turn on.
When I move on to more mission critical switches, Iâd like to make sure that the switch follows the sensor.
Iâm sure that adding a trigger to check the sun state every minute or so would work, Iâm worried that too much looping like this will bog down the piâŚ
these are in my switches.yaml and input_texts.yaml include files
the template switch âgrow_light_onâ follows the text as expected.
However the actual switch âswitch.kitchen_grow_lightâ does not respond to changes in the template switch. (I have tested it in services and it works, as well as with the original automation shown above [remmed out of HA for testing above templates, of course]. }
It never will because thatâs not how a Template Switch works.
The purpose of value_template is to report the current state of the Template Switch. You appear to believe it controls the Template Switchâs turn_on and turn_off functions (it doesnât).
If your concern is that the two automations youâve created might not be triggered due to a badly timed restart, create this additional automation:
that little code will certainly fix some critical things at start. Thank you.
I can accept that âThe purpose of value_template is to report the current state of the Template Switch.â And it appears to do that very well with no lag.
You are correct, I did believe it controls the on/off functions. seems logical to me when I look at it.
But then what is the purpose of the âTurn onâ and âturn offâ functions if they are never used? . What do they do?
In my example the template switch accurately reflects the input_text, and input_text will tether it if I manually toggle it. But the grow_light switch does nothing to the template and vice versa.
They are indeed used, just not in the way you envisioned it. When you turn on a template switch, it executes whatever is defined in the turn_on section.
When you turn on the template switch switch.skylight, it executes the turn_on section which, in this case, turns on switch.skylight_open (but it can be more complex than that).
Sorry, Now Iâm confused again. That sounds like what I first envisioned.
sensor.skylight turn âonâ, template.switch.skylight mimics âonâ and executes itâs turn_on section.
Iâm using a value_template of: â{{ is_state(âinput_text.test_textâ, âonâ) }}â to try to understand this.
when the text is on, (true) the template switch says âonâ. If I type anything other than on, it displays âoffâ.
if I manually flip the template switch to âoffâ when the text is âonâ, the template switch is auto corrected back to âonâ. And vice versa.
So doesnât this prove
the template_switch reports the current state of the value_template (not the other way around)
the template switch is using a true/false test of the value_template to determine what state to display
I want to understand this before I move on to the turn_on and turn_off thingâŚ
The value_template computes the template switchâs state.
The other two parts are executed when the template switch is turned on and off.
Thatâs how it works.
In your original example, the template switch duplicates the functionality of switch.kitchen_grow_light. Not sure why you chose to do this. Is this just an experiment?
yes, just an experiment. I thought it was a neat way to guarantee the state of a physical switch from the state of a sensor and not just trip it once on the sensorâs change of state (like an automation). Iâm using the grow light to experiment with because I can see the results easily.
But I guess that is not the purpose of a template sensor.
Maybe Iâm not understanding what the template switch is,
and what you mean by âThe value_template computes the template switchâs state.â
Here are two screen shots from my frontend.
Isnât the template switch the second one? Itâs following the value_template above it. Toggling the physicalswitch.kitchen_grow_light .has no effect.
What I mean is quite literally what I said. If my attempt to explain it has fallen short, I recommend you read the Template Sensorâs documentation for value_template
I have no idea. Youâre showing screenshots of switches without revealing their configuration. Your original example contained no input_text component but now this one does. I have to assume this example uses a different template not based on sun.sun, as in the original example, but on an input_text. I have no idea what this revised template looks like so I canât comment on the screenshots youâve posted.
Maybe this will help. This example is purposely eccentric in order to make a point.
You have a door thatâs closed (off).
You have a ceiling light thatâs off.
Imagine creating the following template switch:
Its value_template reports the status of the door.
Its turn_on and turn_off portions control a ceiling light switch.
Q: What happens when you turn on the template switch?
A: The ceiling light turns on.
Q: What is the template switchâs status after being turned on?
A: Itâs the doorâs current state so its off.
Unless thereâs some relation between the door and the ceiling light, this template switchâs status will forever be unrelated to the ceiling lightâs status.
If you change the value_template to monitor the ceiling lightâs status, now the template switch will report on whenever the ceiling light turns on. However, this isnât a particularly useful template switch because all it does is mimic the ceiling light switch.
Then it explains why the screenshot shows the template switch reports itâs off. Thereâs no relation between the input_text and switch.kitchen_grow_light.
I think weâre on the same page. Iâm hoping that my lack of understanding is due to the switches just not working. I believe this code to represent your example. However I canât get it to work. I replaced the service calls directly to input_text.set_value to with the scripts just to be sure that I was able to set the value.
Assuming the code is accurate; when I change the âdoorâ status to âopenâ the switch turns on. However nothing effects the light. I canât see why the templateâs turn_on and turn_off are not workingâŚ
I donât think so because you went on to say this:
⌠and weâre back to square one.
Hereâs the deal, your template switch is behaving exactly as it should. However, your preconceived model of how a template switch should work makes you conclude itâs working incorrectly. Itâs not; your preconceived model is incorrect.
Youâre right, Iâm just not seeing how or what turns the light on. Is my code totally off base or is it close enough you could correct it? I can change my understanding of the model when Iâm able to see it workingâŚ
then use automations (the ones you created plus, optionally, the one I offered).
Youâre right, Iâm just not seeing how or what turns the light on.
For starters, definitely not the value_template. You turn a template switch on/of using a service like switch.turn_on or manually via the UI. It isnât turned on/off via its value_template (which serves to report the switchâs status and nothing more).
Is my code totally off base or is it close enough you could correct it?
If youâre referring to the template switch, thereâs nothing to correct. Itâs the wrong tool for the job.
I can change my understanding of the model when Iâm able to see it workingâŚ
How about changing your understanding of the model based on seeing how it does not work? It does not work the way you think it does.