Noy1122
(Noy Jakubovits)
November 23, 2021, 9:19am
1
Hello, I have 2 bed sensors (leg and head) , I want to see how long I slept so I did history stats and its work cool for 1 entity, but sometimes 1 of sensor get on if I put something on the bed so I want to do history stats with 2 entities , In fact I want it to show me history only that the two sensors are active , someone know if I can do it?
Thanks
tom_l
November 23, 2021, 9:48am
2
You don’t say what sort of sensors they are. Assuming they are binary sensors…
Create a binary sensor group of your two sensors and set the all option to true
. This way the group is on only when your two sensors are both on.
Feed your group to the history stats sensor.
Noy1122
(Noy Jakubovits)
November 23, 2021, 10:28am
3
Thanks!
I did it but its not working, this is history stats sensor
you can see the only sensor I changed to group not calculate the time.
this is the code not working:
- platform: history_stats
name: Noy sleep time
entity_id: group.sleep_time_noy
state: 'on'
type: time
end: '{{ now().replace(hour=11, minute=0, second=0) }}'
duration:
hours: 15
and this code working good without group
- platform: history_stats
name: Netta sleep time
entity_id: binary_sensor.top_left
state: 'on'
type: time
end: '{{ now().replace(hour=11, minute=0, second=0) }}'
duration:
hours: 15
- platform: history_stats
name: Noy sleep time1
entity_id: binary_sensor.bottom_right
state: 'on'
type: time
end: '{{ now().replace(hour=11, minute=0, second=0) }}'
duration:
hours: 15
- platform: history_stats
name: Netta sleep time1
entity_id: binary_sensor.bottom_left
state: 'on'
type: time
end: '{{ now().replace(hour=11, minute=0, second=0) }}'
duration:
hours: 15```
What you think the problem?
Thank you very much!
tom_l
November 23, 2021, 10:41am
4
It’s not a group. It’s a binary sensor, if you used this:
It’s the group platform used to create a binary sensor.
Look in developer tools states.
Noy1122
(Noy Jakubovits)
November 23, 2021, 11:00am
5
ohhh, ok I made binary sensor group but its still show me “Unknown”.
this is the new code
binary_sensor:
- platform: group
name: Noy Sleep Time
device_class: opening
entities:
- binary_sensor.top_right
- binary_sensor.bottom_right
all: true
- platform: history_stats
name: Noy sleep time
entity_id: binary_sensor.noy_sleep_time
state: 'on'
type: time
end: '{{ now().replace(hour=11, minute=0, second=0) }}'
duration:
hours: 15
why its not working now?
tom_l
November 23, 2021, 11:15am
6
Test if the group changes state by triggering both binary sensors. This should also update the history stats.
Noy1122
(Noy Jakubovits)
November 23, 2021, 11:22am
7
I tested, its change the state group if i change the entities to on, so the group look right, but I still see unknown in history stats
tom_l
November 24, 2021, 4:31am
8
Huh. That’s weird. Not sure why it is not working. It’s just a binary sensor like any other.
Noy1122
(Noy Jakubovits)
November 24, 2021, 5:45am
9
Oh its ok, I just had to wait a few hours for it to work.
Now its working good!
Thank you!!
1 Like