Get a sensor value on your Apple Watch

I have an Apple Watch and love to use the different complications to get more out of me checking the time. And since I have learned a lot from this forum and HA and also built a nice watering solution for my green house, why not put the soil moisture value right there on my Apple Watch, so I can keep tabs with it and make sure the watering automation is working?

For this I am using the Mi Flora bluetooth plant sensor connected to my HA Raspberry Pi 3 via BLE with Pushover and their Glances API.

To update the value via Glances API I need to make a POST HTTP call containing my keys and the information so I do that with a cURL and a shell script.

shell_command:
  pushmoisture: 'curl --data "token=mytoken&user=myuser&percent={{ states.sensor.cucumber_moisture.state }}" https://api.pushover.net/1/glances.json'

I put this in my configuration.yaml but you can put it in another file for clarity and neatness as long as itā€™s imported into the HA conf file.

Now, the Apple Watch doesnā€™t want to be updated every second out of sake of the battery. This is fine for this purpose since the Mi Flora doesnā€™t update that often either and itā€™s component can set a median value to avoid spikes which gives me a more accurate reading.
This is why I update every half hour, but you can set that as you want. Pushover recommends not more often then 20 minutes between calls.
This is my automation:

  trigger:
  - minutes: '/30'
    platform: time
- action:
  - alias: pushoverglance
    service: shell_command.pushmoisture
  alias: Update complication

Simple, right?
The result is seen in the bottom right as a percentage gauge. Oh, soon time to water the plantsā€¦

IMG_9657

13 Likes

Love this! Thanks for sharing!

Have you tried it with text in the sensor instead of a number/percentage.

I would find this useful to know if my alarm is armed or not at a glance.

Not yet!

But Iā€™m sure Iā€™ll be doing more things with this in the future. And I am pretty sure text wouldnā€™t fit in in that tiny space. But as you know there is larger Pushover complications to add for that and plenty of room for several lines of text.

In your case it should be easy enough to fire when alarm is on or off. Just put something in between so it doesnā€™t fire too often, in case you have to go back in after you activated the alarm because you forgot something.
Happened to us all, Iā€™m sure.

Very cool - Iā€™m sure I can think of a lot of things I can use this technique for!

Thank you!

I am honored to get accolades from you.

BTW, since I got HADashboard running earlier I thought it would be cool if there was an Apple Watch version of HAD. Maybe 4 1x1 tiles on a screen (or 2x1) and then swipe up, down, left, right for more? Another option could be 4 1x1 tiles and then scroll down with the digital crown? With a shortcut via a complication? Could be the ultimate tool for HA.

Sorry, look at me carrying on and interrupting your AppDaemon work.

1 Like

Have you tried using homebridge-homeassistant for use with HomeKit on your Watch? I use it all the time for some favourites. Either from the watch face using the tiles or via Siri on my iPhone or CarPlay when driving.

1 Like

thanks for sharing this i got similar set up but using IFTTT ā€¦is any way to display how many lights are on on my house?

Hey Kem!

Why not share your IFTTT solution?

For the lights, you need something to count the lights, then just pass that value using my way or yours to the Apple Watch.

I found some threads on the subject.

I started playing with this last week, ended up using the modular watch face to include 4 elements available in the Glances API that @jenslj linked to.

Title (Top in blue)
Text (Middle)
Subtext (Bottom)
Percent (Can be anywhere where you can put an icon, in my example itā€™s bottom right and was set to ā€˜countā€™ rather than percentage in my screenshotsā€¦ doh!)

I now have 3 main different modules that change depending on presence at home:

If Iā€™m home:
17-10-06 01-07-15 5680

  • Title: Current Weather Summary at Home

  • Text: Home Energy Consumption in Watts, Nest Thermostat Temperature (Soon to be replaced with a house average across multiple temp sensors), and How many times my letter box was opened today (Between midnight > midnight)

  • SubText: How many lights are on, How many Doors and/or Windows are open

  • Percentage(bottom right): Probability of rain at Home.

If Iā€™m not Home but someone else is Home:
17-10-06 01-15-06 5682

  • Title: Alarm Panel Status, followed by the initials of people at home (could be any combination of 3 other people)

  • Text: Home Energy Consumption in Watts, Nest Thermostat Temperature (Soon to be replaced with a house average across multiple temp sensors), and How many times my letter box was opened today (Between midnight > midnight)

  • SubText: How many lights are on, How many Doors and/or Windows are open

  • Percentage(bottom right): Probability of rain at Home.

When no one is home:
17-10-06 01-18-58 5683

  • Title: Alarm Panel Status, Status of my presence simulation script.

  • Text: How many times someone has triggered front door motion while no one was at home, and How many times my letter box was opened today (Between midnight > midnight)

  • SubText: How many lights are on, How many Doors and/or Windows are open

  • Percentage(bottom right): Probability of rain at Home

Shell Command:

shell_command:
  pushover_glance: 'curl --data "token=token&user=user&title={{ states.sensor.pushover_title_glance.state }}&text={{ states.sensor.pushover_text_glance.state }}&subtext=Lights:{{ states.sensor.lights_on.state }} Door/Win:{{ states.sensor.doors_open.state }}&percent={{ states.sensor.dark_sky_precip_probability.state }}" https://api.pushover.net/1/glances.json'

Sensors:

- platform: template
  sensors:
      
    pushover_title_glance:
      friendly_name: "Alarm Glance"
      value_template: >-
        {% if is_state('input_boolean.mike_home', 'off') %}
          {% if is_state('alarm_control_panel.ha_alarm', 'armed_away') %}Armed Away{% else %}{% endif %}{% if is_state('input_boolean.presence_simulation', 'on') %}:SimON{% else %}{% endif %}{% if is_state('alarm_control_panel.ha_alarm', 'armed_home') %}ArmHome:{% else %}{% endif %}{% if is_state('alarm_control_panel.ha_alarm', 'disarmed') %} {% if is_state('group.household', 'on') %}Home:{% else %}{% endif %} {% if is_state('group.household', 'off') %}House Empty{% else %}{% endif %}{% else %}{% endif %}{% if is_state('alarm_control_panel.ha_alarm', 'pending') %}Pend{% else %}{% endif %}{% if is_state('group.alex', 'home') %}AJ{% else %}{% endif %} {% if is_state('group.joy', 'home') %}JK{% else %}{% endif %} {% if is_state('group.patrick', 'home') %}PK{% else %}{% endif %}
        {% elif is_state('input_boolean.mike_home', 'on') %}
          {% if is_state('alarm_control_panel.ha_alarm', 'disarmed') %}{{ states.sensor.dark_sky_summary.state }}{% else %}{% endif %}{% if is_state('alarm_control_panel.ha_alarm', 'armed_home') %}Armed Home{% else %}{% endif %}
        {% else %}
          Error
        {% endif %}
        
    pushover_text_glance:
      friendly_name: "Pushover Text Glance"
      value_template: >-
        {% if is_state('group.household', 'on') %}
          {{ states.sensor.mains_electricity_energy_usage.state }}w {{ states.climate.living_room.attributes.current_temperature }}Ā° Mail:{{ states.counter.letters_today.state }}
        {% elif is_state('group.household', 'off') %}
          Motion:{{ states.counter.door_motion_away.state }} Mail:{{ states.counter.letters_today.state }}
        {% else %}
          Error
        {% endif %}
        
    lights_on:
      friendly_name: "Lights On"
      value_template: >-
        {% for state in states.light if state.state == 'on' %}{% if loop.last %}{{loop.index}}{% endif %}{% endfor %}
        
    doors_open:
      friendly_name: "Doors Open"
      value_template: >-
        {% for state in states.sensor if state.state == 'open' %}{% if loop.last %}{{loop.index}}{% endif %}{% endfor %}

Counters:

counter:
  letters_today:
    initial: 0
    step: 1

  door_motion_away:
    initial: 0
    step: 1

Automation:

NOTE: Remember to add ā€œsecondsā€ to the time trigger, other wise it will trigger a Pushover API update every second on the half hour (60 times), 86,400 times in a month! limit for free Pushover messages is 7,500 a month, I learnt this the hard way, haha!

- alias: Update Pushover Complication 
  initial_state: 'on'
  trigger:
   - minutes: '/30'
     seconds: 00
     platform: time
  action:
    - service: shell_command.pushover_glance

I have also tagged this as an action:

- service: shell_command.pushover_glance

in automations that trigger on presence changes or alarm state changes (doesnā€™t seem to be using too many API posts to PO) using around 50 a day in total, so 1,500 a month.

This is how Iā€™m using my counters and also resetting them in Automations:

- alias: Front Door Motion Counter While Away
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: binary_sensor.door_cam_motion
    to: 'on'

  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state: 'armed_away'

  action:
    - service: counter.increment
      entity_id: counter.door_motion_away
    - service: shell_command.pushover_glance
      
- alias: Front Door Motion Counter White Away Reset
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.ha_alarm
      from: 'armed_away'
    - platform: time
      at: '00:00:00'
      


  action:
    - service: counter.reset
      entity_id: counter.door_motion_away
    - service: shell_command.pushover_glance
    
- alias: Letters Today Midnight Reset
  initial_state: 'on'
  trigger:
    - platform: time
      at: '00:00:00'

  action:
    - service: counter.reset
      entity_id: counter.letters_today
    - service: shell_command.pushover_glance

It could do with a tidy up, and I think Iā€™ll end up changing things as I find more/less useful features but itā€™s been really handy the last weeks knowing whoā€™s home, how much energy is being used (left the oven on this week and noticed high wattage on watch), how many doors/windows are open before I go to bed and peace of mind with alarm glance.

Hopefully someone will find it useful, adapt, improve, simplify :slight_smile:

Thanks again @jenslj for the inspiration and guide!

7 Likes

this is awesome thanks for taking the time to share this

This would be a relatively straightforward custom component :slight_smile:

1 Like

Thanks for sharing! This is awesome!

1 Like

@badgerhome Iā€™m very impressed with your Apple Watch code and seeing what is possible using sensor templates. Iā€™m creating a more basic version for now as my HA setup isnā€™t as elegant at the moment, but itā€™s a great start so far thanks to your help!

Have you by any chance posted your HA config on GitHub as Iā€™d love to see how youā€™ve set everything up?

Thanks!

Does anyone find that updates to the watch stop happening after a while, and then only reactive when you open the Pushover app on the iPhone? It seems the iOS app needs to be actively running in the background for them to work unfortunately.

Yes, I have the same experience some times.

  1. Is this still available? I donā€™t get value on apple watch but get {{ states.sensor.pushover_title_glance.state }} and so on no value. But there is value display from home assistant.
  2. Do we need to activate the notify pushover as well or donā€™t need as what I read it is glance api.

Thank you very much.

yes is still working

Do I need to use notify pushover platform? or just use the glance api?

In glance api (dashboard), On top has pushover and underneath has create application which one to use?

Furthermore, with the shell_command at the &percent={{ states.sensor.dark_sky_precip_probability.state }} <== I have error with the &percent said that only 0-100 is accepted. However, in dark sky it self show value with % (2 %) on HA frontend, How do we change this?

shell_command:
  pushover_glance: 'curl --data "token=token&user=user&title={{ states.sensor.pushover_title_glance.state }}&text={{ states.sensor.pushover_text_glance.state }}&subtext=Lights:{{ states.sensor.lights_on.state }} Door/Win:{{ states.sensor.doors_open.state }}&percent={{ states.sensor.dark_sky_precip_probability.state }}" https://api.pushover.net/1/glances.json'

Please kindly advice.

i think you need to create an application for your watch because you need the token for that aplication to send any data to glances

I have both user and token. also have registered and pay for IOS device. I did received the pushover message to apple watch (sometimes only) and the message to apple watch not the value display but the title {{ states.sensor.pushover_title_glance.state }} <== display the command instead of the value of the pushover_title_glance and also the text as {{ states.sensor.pushover_text_glance.state }} not the value.