As promised, a little more sofisticated way to update our location. This is also a bit faster since we call the built-in HA REST-API directly instead of using a sensor to check if a folder exists.
If you do this, please remove the “no password” for homebridge user by removing the line you added in the first post
sudo visudo
later revoke the R/W-permissons for the user homebridge to the path that you chose above in post 1
sudo setfacl -m u:homebridge:r /path-in-post-1-where-you-created-the-folder aka "PATH OF CHOICE"/
##Create an input_boolean in HA
input_boolean:
USERishome:
icon: mdi:home
name: Home
##Call HA REST-API
Now create the following .sh files and places them where you want, I placed them in /var/homebridge/ as my congif.json-file is located there:
- USERhome.sh
- USERaway.sh
- USERstatus.sh
USERhome.sh
curl -X POST -H "Content-Type: application/json" -d '{"entity_id":"input_boolean.USERishome"}' "http://IP-to-HA:8123/api/services/input_boolean/turn_on"
USERaway.sh
curl -X POST -H "Content-Type: application/json" -d '{"entity_id":"input_boolean.USERishome"}' "http://IP-to-HA:8123/api/services/input_boolean/turn_off"
USERstatus.sh
curl --silent -X GET "http://IP-to-HA:8123/api/states/input_boolean.USERishome" | grep -i '"state": "on"'
Make all 3 .sh-files excutable, eg.
sudo chmod +x /path/USERstatus.sh
Modify homebridge configuration
Change the following rows that you added in first post
"on_cmd": "/dir-.sh-file/USERhome.sh",
"off_cmd": "/dir-.sh-file/USERaway.sh",
"state_cmd": "/dir-.sh-file/USERstatus.sh"
In my case since I placed the .sh-files in /var/homebridge I modify the config-file according to
"on_cmd": "/var/homebridge/rittehome.sh",
....
Restart homebridge and home-assistant and you’re good to go!
Let me know if any step is unclear, I’ve tested this “improvement” during the evening and it should work as well as the method in post 1, but this is a little more nice solution and quicker since we call the REST-API directly instead of using a sensor that checks if a folder is present or not.