Open Hypfer opened 3 years ago
I second this. The LastActive sensor is too spammy, no one cares when, it's just importat if now it's active or idle. The when can be seen through home assistant on last change time.
{% if (as_timestamp(states.sensor.lastactivenotebook.state).type != NoneType) %} {{ ((as_timestamp(states.sensor.lastactivenotebook.state) - (as_timestamp(now())))|int|abs > 300 ) }} {% else %} {{ false }} {% endif %}
That's how I solved the problem for my automation. I couldn't use states.sensor.lastactivenotebook.state for NOT turning off automatically lights, because when the notebook was turned off, automation was killed (error about NoneType, since the sensor was not available anymore, states.sensor.lastactivenotebook.state could not have now() subctracted anymore, since one was a nonetype and the other was a timestamp).
Thanks for creating an issue! I like the idea of setting a timeout value yourself and then returning a boolean.
Basically, I am using this sensor for NOT turning the light OFF when my girlfriend is actively using her laptop for online courses. When she is not in front of her PC she usually close it, so the sensor turn "unavailable".
I solved it via a template:
alias: Spegni luce cucina senza movimento
trigger:
- device_id: 611d0841b2f84a1eb7668675313ed277
domain: binary_sensor
entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_38e3e501_occupancy
for:
hours: 0
minutes: 15
seconds: 0
platform: device
type: not_occupied
condition:
- condition: or
conditions:
- condition: template
value_template: >-
{% if (as_timestamp(states.sensor.lastactivenotebook.state).type !=
NoneType) %}
{{ ((as_timestamp(states.sensor.lastactivenotebook.state) - (as_timestamp(now())))|int|abs > 300 ) }}
{% else %}
{{ true }}
{% endif %}
- condition: state
entity_id: sensor.lastactivenotebook
state: unavailable
action:
- entity_id: light.tutte_luci_salone
service: light.turn_off
mode: single
I think that the "condition" or is now redundant, I tried it before, I strongly think that the second part of it can be deleted away
Nice workaround!
Currently there's the
LastActive
Sensor which directly reports the value returned byGetLastInputInfo
However, as a user, I actually don't care about the timestamp at all. What I want instead is a boolean that tells me if the session is idle.
Of course this could also be done in HA, however unless excluded from the recorder, using the LastActive sensor like that will quickly fill up the logbook with data that isn't particularly useful
Therefore, I'd propose extending this sensor or adding a new one which takes something like
TimeSpan IdleTime
and provides a boolean that becomestrue
if the last input is older thanNow - IdleTime
.If someone wants different states of idle (possibly away, away, very away, probably gone forever??), they could simply add more instances of this sensor with different names and different
IdleTime
values