Hello, flying to know if anyone can help me with an automation. I have to empty or delete the know devices file every 3 days. Thank you in advance!
The first question is ⌠why?
That said, youâd need to do that from a shell script, and restart Home Assistant afterwards. How you do those depends on how you installed Home Assistant.
the need is because in b & b people connect to WiFi. thus the devices become presence sensors. the cleaning lady will know when they have left. With the passage of time, these devices are increasing more and more and clogging the rows of sensors. thatâs why I would like to automate the file emptying. But you can create a file by restarting HA
Then⌠what install method did you use? Hass.io, Hassbian, Docker, one of the community guides (which one?), something else?
I use a shell script to delete everything below a âflagâ line in known_devices.yaml⌠I make sure everything I want to keep is above the flag otherwise it tends to fill up with spurious stuff⌠depends on which device trackers you use. I define the bash script as a shell command and let an automation call that every time home assistant starts which keeps it under control.
Hi David - are you able to share that script. I would like to be able to do the same thing as the OP. Iâm not expert at Linux so hoping to have something to start fro, rather than googling it all. Any help appreciated
add a shell_command:
shell_command:
clean_knowndevices: /bin/bash /config/clean_knowndevices.sh
add an automation that runs it every time Home Assistant starts:
- id: 'cleanknowndevices'
alias: Clean out Known Devices
trigger:
- event: start
platform: homeassistant
action:
- service: shell_command.clean_knowndevices
In the file known_devices.yaml add this line after all devices you want to keep:
#end-of-my-devices#
Then finally, in the same folder as your configuration.yaml, create clean_knowndevices.sh and add these contents:
#!/bin/sh
/bin/sed -i '/#end-of-my-devices#/q' /config/known_devices.yaml
You will then need to use ssh in that directory to make it executableâŚ
from ssh:
chmod +x clean_knowndevices.sh
Then it will run the script everytime home assistant starts.
Deleting entities is something that I have done several times. My situation is that I have my system set to auto-discovery and I primarily use MQTT (hosted locally) for integration.
As I configure my own IoT sensors and relays, sometimes they are âgrabbedâ by the system before I have given them a proper ID (in the form of a MQTT topic) and the result is several phantom devices lurking around in HA. So I decided to flush the whole thing five days ago and let HA re-discover which devices are actually active. Turned out to be a bad decision since this torpedoed all my automations. Now if I open the automations, the device information has be reset - even though the devices are now back on line. I canât figure out if this is a bug or a feature but I am getting more and more nervous about trusting the HA automations to do anything important. I am considering using my own Node-Red flows or even just write my own automation engine that would sit next to HA (on a different computer) and take care of important automations.
Long story short: âIf devices are deleted (even if only temporary) should the automations be damaged?â Would a sensible alternative not be to âdisableâ the automation in case any of the devices or entities are not found?
If youâre finding that the entities come back with the same Entity and Device ID and the device automations donât work, please open an issue.
Thank you for the recommendation. I will do some testing first to verify that this really is the case. It is good though to get a confirmation that this is NOT the way an Automation should behave. To be continuedâŚ