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

MQTT room presence detection #2913

Merged
merged 11 commits into from
Aug 21, 2016
Merged

Conversation

mKeRix
Copy link
Contributor

@mKeRix mKeRix commented Aug 20, 2016

Description:
This a component for detecting the indoor location of devices with MQTT clients. I have written a sample app at https://github.com/mKeRix/room-assistant (documentation incoming). Basically this component looks for all subtopics in room_presence (or what is configured manually) and then uses that subtopic as room name. The JSON payload (documented for hass.io) is then checked for the id and the distance, where the closest distance will be used as current room. If a scanner stops reporting the device the last distance is on a timeout.

This is fairly cool because it allows us to e.g. turn the lights on/off based on if someone is actually in the room opposed to just being able to control the general presence of being home or not_home. A wearable beacon in combination with a couple RPi 3 make it easy to track anything within the home.

Related issue (if applicable): none

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#810

Example entry for configuration.yaml (if applicable):

# Example configuration.yaml entry
sensor:
  platform: mqtt_room
  device_id: 123testid
  name: 'Cool device'
  state_topic: 'room_presence'
  timeout: 5

Checklist:

If user exposed functionality or configuration variables are added/changed:

If code communicates with devices, web services, or a:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

@mKeRix
Copy link
Contributor Author

mKeRix commented Aug 21, 2016

As discussed with @balloob I converted this device tracker into a sensor to avoid custom core changes.

"""Return the state attributes."""
return {
'distance': self._distance,
'updated': self._updated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this always be updated to the last updated time of the state ?

self.assert_state(LIVING_ROOM)
self.assert_distance(1)

time.sleep(7)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Can't do this. You will delay all tests ever with 7 seconds.

@balloob
Copy link
Member

balloob commented Aug 21, 2016

Looks great 🐬

@balloob balloob merged commit 6aa0789 into home-assistant:dev Aug 21, 2016
@mKeRix mKeRix deleted the mqtt-room-presence branch August 21, 2016 19:26
@home-assistant home-assistant locked and limited conversation to collaborators Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants