Roter
(Roter Raecher)
February 18, 2022, 5:25pm
5
# Den Ordner mit den KNX Geräten einbinden
homeassistant:
packages: !include_dir_named KNXDevices
customize:
binary_sensor.fenster_kuche_template:
device_class: window
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Text to speech
tts:
- platform: google_translate
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
# Custom Panels
panel_custom:
- name: Supervisor
url_path: hassio/system # url_path needs to be unique for each panel_custom config
sidebar_title: Supervisor
sidebar_icon: mdi:home-assistant # https://materialdesignicons.com/
module_url: /local/panel-redirect.js # 'local' is '/config/www/'
binary_sensor:
- platform: template
sensors:
fenster_kuche_template:
friendly_name: "Fenster Küche"
unique_id: "DG2_FensterStatus"
value_template: |
{% if states.binary_sensor.fenster_kuche.state == 'off' %} Geschlossen
{% elif states.binary_sensor.fenster_kuche.state == 'on' %} Offen
{% else %} Unbekannt
{% endif %}
icon_template: |
{% if states.binary_sensor.fenster_kuche.state == 'off' %} mdi:window-closed
{% elif states.binary_sensor.fenster_kuche.state == 'on' %} mdi:window-open
{% else %} mdi:alert-circle
{% endif %}
I added it to my configuration.yaml but I get this error message:
Integration error: customize - Integration ‘customize’ not found.
farmio
(Matthias Alphart)
February 18, 2022, 7:18pm
6
customize
should be a subitem of homeassistant
, not on the same level.
That said, if your binary_sensor.fenster_kuche
is a KNX entity you can just configure that directly. See KNX BinarySensor
If not, you can still customize it directly without the need for a template.
Tinkerer
(aka DubhAd on GitHub)
February 18, 2022, 7:51pm
7
Because you missed the formatting, as farmio said.
homeassistant:
packages: !include_dir_named KNXDevices
customize:
binary_sensor.fenster_kuche_template:
device_class: window
is what you need. YAML is picky about these things
tom_l
February 18, 2022, 11:07pm
8
You don’t have to use customize for this. The device_class
can be added to the template:
binary_sensor:
- platform: template
sensors:
fenster_kuche_template:
friendly_name: "Fenster Küche"
unique_id: "DG2_FensterStatus"
device_class: window #### <------ HERE ###
value_template: |
{% if states.binary_sensor.fenster_kuche.state == 'off' %} Geschlossen
{% elif states.binary_sensor.fenster_kuche.state == 'on' %} Offen
{% else %} Unbekannt
{% endif %}
icon_template: |
{% if states.binary_sensor.fenster_kuche.state == 'off' %} mdi:window-closed
{% elif states.binary_sensor.fenster_kuche.state == 'on' %} mdi:window-open
{% else %} mdi:alert-circle
{% endif %}
https://www.home-assistant.io/integrations/template/#device_class
If all you wan to do is change the original sensor ( fenster_kuche.state
) then use customize, unless it too is defined in YAML (in which case it probably also supports a device_class option).
1 Like
Roter
(Roter Raecher)
February 19, 2022, 2:05pm
9
Thank’s at all!! That helped me. Now it works like I want!! THANKS
330chauf
(330chauf)
September 26, 2023, 7:33am
11
good morning,
Does this formatting still work or did this change with the new formatting?
greets
tom_l
September 26, 2023, 7:46am
12
As per 123’s link above, it is available in the new format.
330chauf
(330chauf)
September 26, 2023, 8:10am
13
Thanks.
So in frontend it indeed shows open or closed while the state is on or off.
However when I try to add the state to a Notification it shows on or off.
{{
states('binary_sensor.lumi_lumi_magnet_acn001_f2bf2500_ias_zone',
'state') }}
how do I get it to show open or closed without creating a sensor of a sensor?
tom_l
September 26, 2023, 8:28am
14
The state is always on or off.
The device class just tells the dashboard how to translate it.
If you want to use something other than the state in your message you have to explicitly choose what to display. Also that template is not the correct way to use states()
.
{{ 'Open' if is_state('binary_sensor.lumi_lumi_magnet_acn001_f2bf2500_ias_zone','on') else 'Closed' }}
2 Likes
330chauf
(330chauf)
September 26, 2023, 8:57am
15
Yep that did the Trick. Thanks a lot. Can I buy you a coffee?
You help so many people so many times
andrex
(Andrea)
January 11, 2024, 6:51pm
16
Using icon_template in a binary sensor it trows me the error
[icon_template] is an invalid option for [binary_sensor]
Has something changed since your post?
123
(Taras)
January 11, 2024, 7:18pm
17
tom_l’s example is for a Template Sensor defined using legacy format which supports icon_template
. In contrast, a Template Sensor defined in modern format supports icon
and not icon_template
.
So if you are using modern format, you have to convert tom_l’s example from legacy to modern format.
tom_l
January 11, 2024, 9:26pm
18
That’s the trouble with old forum posts. Home Assistant changes fast and they go out of date.
You should use the modern format for new sensors.
andrex
(Andrea)
January 12, 2024, 9:03am
19
Hemmm…could you point me to the new format for the binary sensors?
tom_l
January 12, 2024, 9:52am
20
Look at the post directly above mine. Taras linked to both.
andrex
(Andrea)
January 12, 2024, 10:35am
21
Thanks, I’ve missed your reply!
This is the binary sensor (that works):
- name: "Valvola PT"
unique_id: "valvola_pt"
state_topic: "home/centrale_termica/valvole/PT"
value_template: "{{ value_json.value }}"
# device_class: window
payload_on: "1"
payload_off: "0"
And based on the documentation, i’ve created this template:
template:
- binary_sensor:
- name: 'Valvola pt template'
state: >
{{states('binary_sensor.valvola_pt')}}
icon: >
{% if is_state('binary_sensor.valvola_pt', 'on') %}
mdi:valve-open
{% else %}
mdi:valve-closed
{% endif %}
But how can I use this new template? The binary sensor still has the default icon.
Thanks!
123
(Taras)
January 12, 2024, 1:19pm
22
You created a new Template Binary Sensor called binary_sensor.valvola_pt_template
and its icon is determined by the state of binary_sensor.valvola_pt
.
binary_sensor.valvola_pt
is an MQTT Binary Sensor and, according to its documentation , its icon can only be set to one image.
andrex
(Andrea)
January 12, 2024, 1:28pm
23
I’ve lost you.
I’ve discovered that the icon of a binary sensor can’t change when the state changes and when I’ve asked about the icon template you pointed me to the legacy and modern format, but maybe because I’m a newbie, I don’t know how to use the modern format.
The question is: how can I have an entity that changes the icon between valve-open to valve-closed based on a binary sensor?
THANKS!!!
123
(Taras)
January 12, 2024, 4:15pm
24
Explanations have been already been provided (several times) in this topic. If they’re still unclear to you then I suggest you review the documentation (links posted above) while waiting until someone else volunteers to re-phrase the existing explanations.