Weasley Location Clock

Tags: #<Tag:0x00007f77fd2ee3a8>

This isn’t a 100% Home Assistant project, but I did use Home Assistant as an integral part of this project. I built a Weasley Clock like the one in Harry Potter that uses hands on a dial to display the location of my family members.

demo3 (1)

I use the Life360 integration for location and speed data, the unifi integration to track which wifi AP people are attached to, and the HACS Zwift integration to know when people were using Zwift (VR indoor bicycle riding). From that data I determine each person’s location/state and update a sensor. When someone’s Weasley Clock state changes I publish a MQTT event that the physical clock controlled by a raspberry pi and my own custom python code. The Pi then controls some servos that move the hands to the corresponding sector on the clock. When the Pi comes online (boots or the server restarts) it sends an update request to Home Assistant that then publishes all the family member states.

Here’s an example of how one person’s Weasley Clock state is computed:

  #
  # Sensor produces Weasley Clock states
  #
  #  home, garden, school, work, intransit, mortalperil, lost, error
  # 
  #  home/school/work/lost/intransit/lost is determined by life360 location
  #  garden is based on which of the home WiFi access points is being used
  #  mortalperil is triggered by life360 detecting speeds over 75
  #  error is triggered if the life360 device_tracker returns None type
  #  
  - platform: template
    sensors:
      weasley_clock_user1:
        entity_id:
          - sensor.home_ap_user1
          - device_tracker.life360_user1
        icon_template: >-
          {% set icon = 'mdi:clock-outline' %}
          {% set s = 'sensor.weasley_clock_user1' %}
          {% if states(s) == 'school' %}
          {%   set icon = 'mdi:school' %}
          {% elif states(s) == 'home' %}
          {%   set icon = 'mdi:home' %}
          {% elif states(s) == 'barn' %}
          {%   set icon = 'mdi:barn' %}
          {% elif states(s) == 'lost' %}
          {%   set icon = 'mdi:map-marker-question' %}
          {% elif states(s) == 'intransit' %}
          {%   set icon = 'mdi:train-car' %}
          {% elif states(s) == 'work' %}
          {%   set icon = 'mdi:briefcase' %}
          {% elif states(s) == 'garden' %}
          {%   set icon = 'mdi:flower' %}
          {% elif states(s) == 'mortalperil' %}
          {%   set icon = 'mdi:speedometer' %}
          {% elif states(s) == 'quidditch' %}
          {%   set icon = 'mdi:broom' %}
          {% endif %}
          {{ icon }}
        value_template: >-
          {%- set home_ap_sensor = 'sensor.home_ap_user1' %}
          {%- set tracker = 'device_tracker.life360_user1' %}
          {%- set ns = namespace(wc='lost') %}
          {%- set state = states( tracker ) %}
          {%- if not state %}
          {%-   set ns.wc = 'error' %}
          {%- elif state == 'home' %}
          {%-   set home_ap = states( home_ap_sensor ) %}
          {%-   if home_ap == 'GardenAP' %}
          {%-       set ns.wc = 'garden' -%}
          {%-   else %}
          {%-       set ns.wc = 'home' -%}
          {%-   endif %}
          {%- elif state == 'moving' or state == 'driving' %}
          {%-   set ns.wc = 'intransit'  %}
          {%-   set speed  = state_attr( tracker, 'speed') %}
          {%-   if speed and speed > 75 %}
          {%-     set ns.wc = 'mortalperil' %}
          {%-   endif %}
          {%- else %}
          {%-   set place = state.lower() %}
          {%-   if place == 'your local high school' or place == 'your local middle school'%}
          {%-     set ns.wc = 'school' %}
          {%-   elif place == 'work' %}
          {%-     set ns.wc = 'work' %}
          {%-   else %}
          {%-     set ns.wc = 'lost' %}
          {%-   endif %}
          {%- endif -%}
          {{ ns.wc }}
1 Like

Crazy cool!

1 Like

This is really awesome !
I’ll will keep it in my “Todo” project list for when I find time !

1 Like