Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appdaemon script #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions appdaemon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Appdaemon (v3.0.0)](https://appdaemon.readthedocs.io/en/latest/) script that listens for changes in the average confidence of a person's presence. It uses MQTT to report back to Home Assistant via the [Device Tracker MQTT Component](https://www.home-assistant.io/components/device_tracker.mqtt/).

Copy the contents of the files to your sensors.yaml, device_tracker.yaml and apps.yaml file. Change the file to your liking and copy the appdaemon file to the apps folder.
13 changes: 13 additions & 0 deletions appdaemon/apps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
person1_device_tracker:
module: mqtt_device_tracker
class: mqtt_device_tracker
trigger: sensor.person1_home_occupancy_confidence
device: device_tracker.phone_person1
device_topic: "/location/person1"

person2_device_tracker:
module: mqtt_device_tracker
class: mqtt_device_tracker
trigger: sensor.person2_home_occupancy_confidence
device: device_tracker.phone_person2
device_topic: "/location/person2"
4 changes: 4 additions & 0 deletions appdaemon/device_tracker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- platform: mqtt
devices:
phone_sander: "/location/person1"
phone_linda: "/location/person2"
26 changes: 26 additions & 0 deletions appdaemon/mqtt_device_tracker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import appdaemon.plugins.hass.hassapi as hass


class mqtt_device_tracker(hass.Hass):
def initialize(self):
self.listen_state(self.inputhandler, self.args["trigger"])

def inputhandler(self, entity, attribute, old, new, kwargs):
confidence = float(self.get_state(self.args["trigger"]))
state = self.get_state(self.args["device"])
device_topic = self.args["device_topic"]

device = self.args["device"]

# self.log(device)
# self.log(confidence)
# self.log(state)

if state == "not_home" and confidence > 10:
# self.log(device_topic)
# self.log("home")
self.call_service("mqtt/publish", topic=device_topic, payload="home")
elif state == "home" and confidence <= 10:
# self.log(device_topic)
# self.log("not_home")
self.call_service("mqtt/publish", topic=device_topic, payload="not_home")
22 changes: 22 additions & 0 deletions appdaemon/sensors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- platform: mqtt
state_topic: '/presence/owner/room/xx:xx:xx:xx'
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'Person1 room'
- platform: mqtt
state_topic: '/presence/owner/room/xx:xx:xx:xx'
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'person2 room'
- platform: min_max
name: "Person1 Home Occupancy Confidence"
type: mean
round_digits: 0
entity_ids:
- sensor.person1_woonkamer
- platform: min_max
name: "Person2 Home Occupancy Confidence"
type: mean
round_digits: 0
entity_ids:
- sensor.person2_woonkamer