Hello everyone,
This is my first post and my first script.
I made a simple script to transfer my UPS status to my Polisy unit.
On the Polisy I created a state variable that I can write to from the HA script. Simple.
Here is the script I have so far:
The problem I have is the value of sensor.cp1350avr_status lists all active states in the same string.
For example, I can have:
āOnlineā or āOnline Battery Chargingā or āOnline Battery Charging Low Batteryā or āOn Battery Battery Dischargingā, etc.
Iād like to be able to separate each state.
For example, is there a way to find āOnlineā in the state string?
@finity Thanks again. The template condition works. Iād like to go a bit further and combine two UPS status condition into one ISY variable. For example, Iād like to do something like:
{{ 'Battery Charging' or 'Battery Discharging' in states('sensor.cp1350avr_status') }}
I tried it and it doesnāt work. I always get a false result.
How should I modify the value_template?
Itās looking for that exact string contained within the state string.
So for example you had a sentence (a string):
āthe state of the entity canāt be both Battery Charging and Battery Discharging at the same timeā
to construct a template to check for either of those phrases you would do this:
{% set string = "the state of the entity can't be both Battery Charging and Battery Discharging at the same time" %}
{{ 'Battery Charging' in string or 'Battery Discharging' in string }}
in this case it would return true (finds both phrases).
but if you changed it to this:
{% set string = "the state of the entity can't be both Battery is Charging and Battery is Discharging at the same time" %}
{{ 'Battery Charging' in string or 'Battery Discharging' in string }}
the template returns false (it finds neither phrase).
or:
{% set string = "the state of the entity can't be both Battery Charging and Battery is Discharging at the same time" %}
{{ 'Battery Charging' in string or 'Battery Discharging' in string }}
would be true (it finds āBattery Chargingā but not āBattery Dischargingā).
you can play around with it in the dev tools template editor to find the right combinations.
Thanks @finity, before reading your post I tried a few things that didnāt work because I didnāt have the proper syntax. I was editing directly in YAML. I tried the scriptās web interface and realized that the proper syntax is like this: