jagiel
(Jagiel)
November 8, 2018, 1:47pm
1
hi, before update (from 81.1) to 81.6 all works fine, now i have problem:
Template sensor window_count has no entity ids configured to track nor were we able to extract the entities to track from the value template(s). This entity will only be able to be updated manually.
works before update:
platform: template
sensors:
door_count:
value_template: >-
{{ states.binary_sensor | selectattr(‘state’, ‘eq’, ‘on’) | selectattr(‘attributes.device_class’, ‘eq’, ‘door’) | list | count | int }}
window_count:
value_template: >-
{{ states.binary_sensor | selectattr(‘state’, ‘eq’, ‘on’) | selectattr(‘attributes.device_class’, ‘eq’, ‘window’) | list | count | int }}
whats changed?
petro
(Petro)
November 8, 2018, 2:00pm
2
This was covered in the breaking changes sections. You need to list out all the sensors in order for it to update properly.
jagiel:
whats changed?
They fixed issues with templates. Template <insert component
> shouldn’t have been updating without a list of entities to trigger the updates.
To fix your issues, list out the entity_ids that us the door/window device class under the entity_id attribute for your sensors.
jagiel
(Jagiel)
November 8, 2018, 2:02pm
3
did u know how to change this code?
for example:
binary_sensor.door_window_sensor_158d0003
binary_sensor.door_window_sensor_158d0002
finity
November 8, 2018, 3:19pm
4
like this should work:
- platform: template
sensors:
door_count:
entity_id:
- binary_sensor.door_window_sensor_158d0003
- binary_sensor.door_window_sensor_158d0002
value_template: >-
{{ states.binary_sensor | selectattr('state', 'eq', 'on') | selectattr('attributes.device_class', 'eq', 'door') | list | count | int }}
window_count:
entity_id:
- binary_sensor.door_window_sensor_158d0003
- binary_sensor.door_window_sensor_158d0002
value_template: >-
{{ states.binary_sensor | selectattr('state', 'eq', 'on') | selectattr('attributes.device_class', 'eq', 'window') | list | count | int }}
You’ll need to decide which entities are in the 'window type & which are in the ‘door’ type.
1 Like
petro
(Petro)
November 8, 2018, 4:10pm
5
Also, apparently there is a new service that can be called:
Template sensors for which we could not determine what states to track to re-render will now only be updated when manually refreshed using the new homeassistant.update_entity
service. (@balloob - #17276 ) (sensor.template docs ) (breaking change)
jagiel
(Jagiel)
November 8, 2018, 6:52pm
6
last question, how to count other type sensors like switch (sonoff t1) and led (yeelight)? its all light
as i understand the clou is class type attributes.device_class:
lights_count:
entity_id:
- switch.espurna_adbc_0
- switch.espurna_adbc_1
- light.kitchen_led
- light.gateway_light_78d87df
- switch.lamp1
value_template: >-
{{ states.binary_sensor | selectattr('state', 'eq', 'on') | selectattr('attributes.device_class', 'eq', '???????') | list | count | int }}
petro
(Petro)
November 8, 2018, 7:15pm
7
You could place all the devices into a group, then use the group as your filter:
{{ states | selectattr('entity_id','in',state_attr('group.mygroup','entity_id')) | selectattr('state','eq','on') | list | count }}
petro
(Petro)
November 8, 2018, 7:18pm
8
or if you are super lazy and you only have lights and switches, this would work out of the box:
{{ states | selectattr('entity_id','in', state_attr('group.all_lights','entity_id') + state_attr('group.all_switches','entity_id')) |selectattr('state','eq','on') | list | count }}
CSG
(Christoph Gruss)
November 20, 2018, 4:39pm
9
I used your code and it works great and all lights are counted correctly. Thanks
But now I would like to send the outcome of the sensor to my GIRA KNX Quadclient to use the information in the application as a Kommunication Object (KO) and not as a sensor or switch.
So the question is how can I send the information to the KNX bus of a KO “Number of light on” of a changed value without being it a sensor or switch?
petro
(Petro)
November 20, 2018, 5:11pm
10
probably should start by looking at the knx integration
CSG
(Christoph Gruss)
November 20, 2018, 8:53pm
11
thanks. KNX components are already integrated and it works. However for this Question I miss the answer as it is None of the listed KNX components as the sensor (which I created in HA) does not have a KNX comparison. I just want to disclose the same value in my GIRA(KNX) app that I have in the HA app. Maybe it is very simple but I do not get it Right now
petro
(Petro)
November 20, 2018, 11:13pm
12
I’m not sure, never used KNX.
I would expect it to be this portion of the documentation:
KNX component is able to expose time or sensor values to KNX bus. The component will broadcast any change of the exposed value to the KNX bus and answer read requests to the specified group address:
# Example configuration.yaml entry
knx:
expose:
- type: 'temperature'
entity_id: 'sensor.owm_temperature'
address: '0/0/2'
- type: 'time'
address: '0/0/1'
- type: 'datetime'
address: '0/0/23'
gmario
(GMario)
April 15, 2019, 1:14pm
13
You can use entity_id: []
in your templates to avoid this message.
Check the official doc .
platform: template
sensors:
door_count:
entity_id: []
value_template: >
{{ states.binary_sensor | selectattr(‘state’, ‘eq’, ‘on’) | selectattr(‘attributes.device_class’, ‘eq’, ‘door’) | list | count | int }}
petro:
{{ states | selectattr(‘entity_id’,‘in’,state_attr(‘group.mygroup’,‘entity_id’)) | selectattr(‘state’,‘eq’,‘on’) | list | count }}
Hi, currently using this but it seems to only provide a count of 1, even though my group contains multiple open windows. Any ideas? Thanks in advance!
petro
(Petro)
May 21, 2019, 12:10pm
15
is the state of these windows ‘on’? or is the state something else?
Yes, the state is ‘on’ when open and ‘off’ when closed. But the sensor only shows ‘1’.
Here is my code.
group:
window_sensors:
name: Windows
control: hidden
entities:
- binary_sensor.0x00158d0002e9e1a9_contact
- binary_sensor.0x00158d0002c8d6a4_contact
- binary_sensor.0x00158d0002ea3460_contact
- binary_sensor.0x00158d0002e9e092_contact
- binary_sensor.0x00158d0002e9c9ee_contact
- binary_sensor.0x00158d0002ea9ebf_contact
- binary_sensor.0x00158d0002ea0766_contact
- binary_sensor.0x00158d0002e9e2f0_contact
- binary_sensor.0x00158d0002e9e010_contact
sensor:
- platform: template
sensors:
window_count:
value_template: >-
{{ states | selectattr('entity_id','in',state_attr('group.window_sensors','entity_id')) | selectattr('state','eq','on') | list | count }}
petro
(Petro)
May 21, 2019, 12:28pm
17
sensor is inside the group catagory, you need to make it it’s own catagory. You’ll also need to add all the sensors in the group to the template as a list.
group:
window_sensors:
name: Windows
control: hidden
entities:
- binary_sensor.0x00158d0002e9e1a9_contact
- binary_sensor.0x00158d0002c8d6a4_contact
- binary_sensor.0x00158d0002ea3460_contact
- binary_sensor.0x00158d0002e9e092_contact
- binary_sensor.0x00158d0002e9c9ee_contact
- binary_sensor.0x00158d0002ea9ebf_contact
- binary_sensor.0x00158d0002ea0766_contact
- binary_sensor.0x00158d0002e9e2f0_contact
- binary_sensor.0x00158d0002e9e010_contact
sensor:
- platform: template
sensors:
window_count:
entity_id:
- binary_sensor.0x00158d0002e9e1a9_contact
- binary_sensor.0x00158d0002c8d6a4_contact
- binary_sensor.0x00158d0002ea3460_contact
- binary_sensor.0x00158d0002e9e092_contact
- binary_sensor.0x00158d0002e9c9ee_contact
- binary_sensor.0x00158d0002ea9ebf_contact
- binary_sensor.0x00158d0002ea0766_contact
- binary_sensor.0x00158d0002e9e2f0_contact
- binary_sensor.0x00158d0002e9e010_contact
value_template: >-
{{ states | selectattr('entity_id','in',state_attr('group.window_sensors','entity_id')) | selectattr('state','eq','on') | list | count }}
Sorry my indentation was off earlier. So I still have to retain a list of entity_id’s within the template sensor? I thought the group effectively became the list with this approach?
Here is my full code
## Groups
group:
alarm:
name: Home Alarm
control: hidden
entities:
- alarm_control_panel.home_alarm
- sensor.door_count
- sensor.window_count
- sensor.alarm_panel_online
motion_sensors:
name: Motion
control: hidden
entities:
- binary_sensor.entry_motion
- binary_sensor.0x00158d00020b767f_occupancy
- binary_sensor.0x00158d00022809ec_occupancy
- binary_sensor.living_room_motion
- binary_sensor.0x00158d00022809d8_occupancy
- binary_sensor.0x00158d000223ed18_occupancy
- binary_sensor.0x00158d00022809cc_occupancy
- binary_sensor.0x00158d00020b76b1_occupancy
- binary_sensor.master_bedroom_motion
door_sensors:
name: Doors
control: hidden
entities:
- binary_sensor.garage_side_entry_door
- binary_sensor.0x00158d000239f6bd_contact
- binary_sensor.0x00158d00023dbef6_contact
- binary_sensor.0x00158d000239f6ee_contact
- binary_sensor.0x00158d000239cb52_contact
window_sensors:
name: Windows
control: hidden
entities:
- binary_sensor.0x00158d0002e9e1a9_contact
- binary_sensor.0x00158d0002c8d6a4_contact
- binary_sensor.0x00158d0002ea3460_contact
- binary_sensor.0x00158d0002e9e092_contact
- binary_sensor.0x00158d0002e9c9ee_contact
- binary_sensor.0x00158d0002ea9ebf_contact
- binary_sensor.0x00158d0002ea0766_contact
- binary_sensor.0x00158d0002e9e2f0_contact
- binary_sensor.0x00158d0002e9e010_contact
## Sensors
sensor:
- platform: template
sensors:
door_count:
value_template: >-
{{ states | selectattr('entity_id','in',state_attr('group.door_sensors','entity_id')) | selectattr('state','eq','on') | list | count }}
# {{ states | selectattr('entity_id','in',state_attr('group.door_sensors','entity_id')) | selectattr('state','eq','on') | list | count | int}}
# entity_id:
# - binary_sensor.0x00158d000239cb52_contact
# - binary_sensor.0x00158d000239f6bd_contact
# - binary_sensor.0x00158d000239f6ee_contact
# - binary_sensor.0x00158d00023dbef6_contact
# - binary_sensor.garage_side_entry_door
window_count:
value_template: >-
{{ states | selectattr('entity_id','in',state_attr('group.window_sensors','entity_id')) | selectattr('state','eq','on') | list | count }}
# {{ states | selectattr('entity_id','in',state_attr('group.window_sensors','entity_id')) | selectattr('state','eq','on') | list | count | int}}
# entity_id:
# - binary_sensor.0x00158d0002e9e1a9_contact
# - binary_sensor.0x00158d0002c8d6a4_contact
# - binary_sensor.0x00158d0002ea3460_contact
# - binary_sensor.0x00158d0002e9e092_contact
# - binary_sensor.0x00158d0002e9c9ee_contact
# - binary_sensor.0x00158d0002ea9ebf_contact
# - binary_sensor.0x00158d0002ea0766_contact
# - binary_sensor.0x00158d0002e9e2f0_contact
# - binary_sensor.0x00158d0002e9e010_contact
alarm_panel_online:
friendly_name: 'Alarm Panel'
value_template: "{% if states.device_tracker.alarm_panel %}
{% if is_state('device_tracker.alarm_panel', 'home') %}
Online
{% else %}
Offline
{% endif %}
{% else %}
Unknown
{% endif %}"
petro
(Petro)
May 21, 2019, 2:19pm
19
Yes, otherwise the sensor will never update because it has nothing to update against. Template sensors update when reference entities update. This only has 1, the group. The group will only update when switching to from off to on or on to off. That does not always occur because if one item is on and another turns on, the groups state does not change.
1 Like