PickOne
December 30, 2020, 10:48am
1
Hi guys!
I have a broadlink device which show me the value of the light sensor, which have only 4 states (0, 1, 2, 3). I configured a card in lovelace, but I want to see something else, not numbers. I want to see “Dark” is is 0, “Normal” if is 1, “Bright” if is 2, “Extremely Bright” if is 3. How can I do this? I don’t understand exactly, i’m very new to this Home Assistant world… So take me easy
Thank you in advance
sender
December 30, 2020, 11:00am
2
Take a look at sensor templates
PickOne
December 30, 2020, 11:10am
3
Please explain to me, i’m very new to this…
tom_l
December 30, 2020, 11:30am
5
Try this (change the sensor to the one you have that gives the 0 to 3 reading):
sensor:
- platform: template
sensors:
light_level:
friendly_name: "Light Level"
value_template: >
{{ ['Dark', 'Normal', 'Bright', 'Extremely Bright'][states('sensor.your_light_sensor_here')] }}
PickOne
December 30, 2020, 11:40am
6
It is not showing me any state, for this new sensor …
tom_l
December 30, 2020, 11:44am
7
Try this:
sensor:
- platform: template
sensors:
light_level:
friendly_name: "Light Level"
value_template: >
{{ ['Dark', 'Normal', 'Bright', 'Extremely Bright'][states('sensor.your_light_sensor_here')|int] }}
1 Like
PickOne
December 30, 2020, 11:46am
8
You are the man !!!
I was trying to make this possible with conditions, like if 3, then “Very Bright”, but your approaching with array it is far better… Thank you so much
tom_l
December 30, 2020, 11:47am
9
No problem. Do you need an explanation for how it works?
PickOne
December 30, 2020, 11:49am
10
No, it is clear… using an array, it is from first to last, like 0 to 3.
1 Like
Hi Tom, can you please help me with something similar?
I want to make a custom switch to toggle alarm panel to armed/disarmed, and I want the switch to have the real state, in on/off only
I have done something like this, but it is not working…
alarm_toggle:
value_template: >-
{{ ['off', 'on', 'on']['disarmed', 'arming', 'armed_away'] }}
turn_on:
service: script.alarm_arm
turn_off:
service: script.alarm_disarm
Thank you in advance
I think I managed to do it like this
value_template: >-
{% if is_state('alarm_control_panel.ha_alarm', 'arming') or is_state('alarm_control_panel.ha_alarm', 'armed_away') %}
on
{% elif is_state('alarm_control_panel.ha_alarm', 'disarmed') %}
off
{% endif %}
turn_on:
service: script.alarm_arm
turn_off:
service: script.alarm_disarm
But I don’t know if this is the proper solution… If you have another, simplier alternative, please tell me. Thank you!