I am trying to write template switches to control my shades, depending on whether heat gain or retention is needed. The first is called Solar Gain Heat, and should turn on when the solar radiation is above a certain value and temperatures are above or below other values. The template switches are in the file switches.yaml which configuration.yaml includes.
This switch always shows as unavailable even though the solar radiation sensor is available and a number (currently 33). I think I may have the syntax wrong on the value template.
My other problem is that I need the switch to trigger on only when several conditions are met: radiation above 100, wall temperature below 60, outside air temperature below 50, and inside air temperature below 75. How would I chain value templates in the one switch? Thanks for help.
This is definitely not valid. You never actually get the state of sensor.sky_solar_radiation for one, you’re just using that text. Also you’re using '| float > 100' as a string which doesn’t really do anything and passing it to is_number as a second argument when it only takes one.
I think this is a correct version of that template:
If somehow sensor.sky_solar_radiation does not have a numeric state it will default that to -1 which is less then 100. Alternatively you can add this as the availability_template to mark the switch as unavailable when the state of that entity is non-numeric:
{{ states('sensor.sky_solar_radiation') is float }}
You can’t chain multiple value_templates, you just make a bigger template. Pipe things from one to another, use ands and ors, set things to variables and then use those variables, etc. Have you taken a look at HA’s templating doc and Jinja’s? It shows a lot of examples of how to make templates as well as what operators, tests and filters are available.
Also this whole statement is a bit confusing. You’re aware that the script.shades_open_all service is only called when the switch is actually turned on either by a user in the UI or when an automation/script calls switch.turn_on on it, right?
It is not going to call script.shades_open_all when your value_template evaluates to true. The value_template is HA’s way of determining the current state of the switch, it does not trigger either the turn_on or turn_off service. The idea is that when the user/script/automation turns on the switch it causes something to change which then makes value_template evaluate to on (or vice versa if turning it off). But if something changes which causes the value_template to change without anyone or anything calling the turn_on or turn_off service then the switch just changes state and that’s all that happens.
If what you’re hoping is that script.shades_open_all is called when radiation is above 100, wall temp is below 60, outside air below 50 and air temp below 75 then you don’t want a template switch at all. That’s just an automation with a template trigger
I can easily fine tune the parameters and duplicate this for the other modes of shade control. These are: retain heat (all shades down at night), shed heat (all shades up at night), and shun heat (upper shades down during day). The windows total over 150 sq. ft. (14 sq. meters) and I live in sunny Colorado, so shade control makes a big difference. The wall temperature is taken from an ESP sensor placed within the E-crete wall. This material is a foamed concrete that acts like adobe, absorbing heat during the day and releasing it at night.