sleevezipper / hass-workstation-service

Provide useful sensors and services from your workstation to Home Assistant.
Apache License 2.0
613 stars 54 forks source link

Device_tracker based on mqtt last will topic #105

Closed fabsenet closed 3 years ago

fabsenet commented 3 years ago

Hi,

can you add a sensor which will only send "on" or something but also has a last will of "off" so this can be used as a faster device_tracker for the PC? currently I am using discovery of my router (fritz) and with that, it stays online for 180s after shutdown.

Would be great!

manju-rn commented 3 years ago

State management is best done in a central place. If you are using Home Assistant, you could always use automation there or store the values. I would assume that adding DB level capabilities in current service which is performing so efficiently would needlessly bloat and may affect efficiency in future or system with low specs

With that said, I think this kind of arrangement should be for linux systems as well

fabsenet commented 3 years ago

@manju-rn I either failed to made my request understandable in the first place or I am now unable to understand any of your comment, sorry

fabsenet commented 3 years ago

to solve my problem, I noticed all sensors become unavailable whenever the pc is not reachable or simply powered down. I use that as a self made on/off info. See the value_template in my template switch. The switch position follows the powered on/off state of the pc.

switch:
  - platform: template # https://www.home-assistant.io/integrations/switch.template/
    switches:
      mysuperswitch:
        value_template: '{% if states("sensor.myrandomsensor")!="unavailable" %}on{% else %}off{% endif %}'
....snipped
sleevezipper commented 3 years ago

Thanks for creating an issue!

It would certainly be possible to add a sensor with a different Last Will message to serve as a device tracker but I'm not entirely convinced to assume unavailable == off. At least, not for all devices and all users. In your template sensor you do exactly that because it makes sense for your situation and it's a good solution for that. I'll close this for now, please reopen if you don't agree :)