TheStigh
(TheStigh)
August 11, 2023, 4:28pm
1
Hi,
I’ve started rewriting my template sensors, but can’t get this to work.
configuration.yaml:
template: !include_dir_merge_list includes/templates/
Currently, in the folder /includes/templates/
I only at the moment have a single .yaml file (but will be more individual files)
f711b.yaml:
- sensor:
- unique_id: zflip_location_state
name: Siv ZFlip
state: >
{%- if states.person.siv.state == 'home' %}
Hjemme
{%- endif %}
- unique_id: zflip_battery_level_power
name: Strømlader
state: >
{%- set power_status = states.binary_sensor.sm_f711b_is_charging.state %}
{%- if power_status == 'off' %}
Frakoplet
{%- else %}
Tilkoplet
{%- endif %}
device_class: battery
icon: >
{%- set power_status = states.binary_sensor.sm_f711b_is_charging.state %}
{%- if power_status == 'off' %}
mdi:battery-off-outline
{%- else %}
mdi:battery-charging-outline
{%- endif %}
Anybody spot what I’m doing wrong?
When I test the template in the Template editor, it give me the correct value, but after loading the configuration, I do not get any new sensor named zflip_battery_level_power
or stromlader
.
None of the two template sensors above work…
Of course, I’ve checked that binary_sensor.sm_f711b_is_charging report anything, which current value off
francisp
(Francis)
August 11, 2023, 4:36pm
2
First time you use template: , you have to restart HA.
TheStigh
(TheStigh)
August 11, 2023, 4:41pm
3
Hehe, done several restarts
petro
(Petro)
August 11, 2023, 4:53pm
4
It’s going to be named sensor.stromlader
.
TheStigh
(TheStigh)
August 11, 2023, 5:16pm
5
Ain’t there… Really confused. That’s why I had to raise this here. I’ve even looked at your git @petro and can’t find anything wrong…
123
(Taras)
August 11, 2023, 6:49pm
6
Is includes
a sub-directory of the directory containing configuration.yaml
?
It must be in order for this to work:
finity
August 12, 2023, 3:15am
7
Maybe it doesn’t understand:
ø
and replaces it with an underscore?
try looking for a ‘sensor.str*mlader’
TheStigh
(TheStigh)
August 13, 2023, 7:25pm
8
Nop, not related.
Even the sensor above in my example above are not created. No error in the logs.
TheStigh
(TheStigh)
August 14, 2023, 12:15am
9
@petro Pls try to help me out here
I moved it all directly to configuration.yaml
and tested this:
template:
- sensor:
- unique_id: sm_s908b_battery_level_charging
name: Ladestatus Stigh
state: >
{% set power_charging = states.sensor.sm_s908b_battery_state.state %}
{% if power_charging == 'discharging' %}
Frakoplet
{% else %}
Lader
{% endif %}
device_class: battery
icon: >
{% set power_charging = states.sensor.sm_s908b_battery_state.state %}
{% if power_charging == 'discharging' %}
mdi:power-plug-off
{% else %}
mdi:power-plug
{ % endif %}
I also tried with
template:
- sensor:
- unique_id: sm_s908b_battery_level_charging
name: Ladestatus Stigh
state: >
{-% set power_charging = states.sensor.sm_s908b_battery_state.state %}
{-% if power_charging == 'discharging' %}
Frakoplet
{-% else %}
Lader
{-% endif %}
device_class: battery
icon: >
{-% set power_charging = states.sensor.sm_s908b_battery_state.state %}
{-% if power_charging == 'discharging' %}
mdi:power-plug-off
{-% else %}
mdi:power-plug
{-% endif %}
Checked sensor.sm_s908b_battery_state
and it updates when connecting and disconnecting charger.
Still no sensor called ladestatus_stigh
… and no error in the log, even with debug.
I’m out of options…
petro
(Petro)
August 14, 2023, 11:56am
10
Well for 1, you can’t use device_class: battery for text based sensors. The battery device class is for % sensors that represent a batteries life from 0 to 100%. You’d see errors in the logs saying “non numerical blah blah”.
TBH, these should be binary_sensors with a device_class: power.
template:
- binary_sensor:
- unique_id: sm_s908b_battery_level_charging
name: Ladestatus Stigh
state: "{{ not is_state('sensor.sm_s908b_battery_state', 'discharging') }}"
device_class: power
secondly, make sure you have 1 template section, not 2.
TheStigh
(TheStigh)
August 14, 2023, 5:55pm
11
Hi @petro
Can’t I have the template (as earlier) to return a sensor
?
What I’m trying are to make a custom state (text) rather than the original istate.
The device class was never intended to be there, frankly I do not know why it was there
Only got 1 template section
petro
(Petro)
August 14, 2023, 6:13pm
12
You can, but not as device class battery. So just remove that
TheStigh
(TheStigh)
August 15, 2023, 10:03am
13
@petro
Found it!
I’m on my way to reset myself to factory default - so embarrassed…
Hidden in a galaxy far far away, thousands of years ago, there was another template:
in configuration.yaml
1 Like