Home Assistant - Using Input Number to trigger automations

Home Assistant - Using Input Number to trigger automations

Hi everyone,

In this article we have seen how to define a value using the Input Number integration.

Today we'll see how to use Input Number as dynamic values to trigger automations.

Scenario

You want to get notified when the battery of your smartphone reaches a value you can dynamically set / modify as you need via the Home Assistant user interface.

Software configuration

  1. Home Assistant. I'm currently running version?2022.8.7.
  2. Mobile App integration?configured in Home Assistant. This integration allows Home Assistant mobile APP (Android / IOS) to integrate with your Home Assistant environment.
  3. The Home Assistant companion app must be configured to have the?battery level?sensor?enabled.
  4. Input Number SmartphoneBatteryThresholdMax and SmartphoneBatteryThresholdMin defined and available in your Home Assistant dashboard so that you can set them on the fly.

Home Assistant code (yaml) / procedure

This is the piece of code you have to write as?Automation:

alias: >
? Smartphone - Send an Android notification if the battery level overcomes   the threshold (min/max) set as Input Number helpers
description: >-
? Send an Android notification if the battery level overcomes the threshold (min/max) set as Input Number helpers
trigger:
? - platform: template
? ? value_template: >
? ? ? {{ states('sensor.yoursmartphone_battery_level')|float? >
? ? ? states('input_number.SmartphoneBatteryThresholdMax')|float }}
? - platform: template
? ? value_template: >
? ? ? {{ states('sensor.yoursmartphone_battery_level')|float? <
? ? ? states('input_number.SmartphoneBatteryThresholdMin')|float }}
condition: []
action:
? - service: notify.mobile_app_yoursmartphone
? ? data:
? ? ? message: >-
? ? ? ? The battery level is at?
? ? ? ? {{states("sensor.yoursmartphone_battery_level") }}%. Shut-off charging or give your phone a recharge.
mode: single

-        

Some specifics about the code / procedure above

  1. As you can see the automation triggers are now based on the Input Number defined so the trigger itself can dinamically change according to the values set.
  2. The action is to send a notification to your smartphone with the battery charge level reached.

Thank you for reading. ?? I hope you have enjoyed this article.

I'm available for any feedback so, feel free to contact me or share your thoughts in the comments section below.

Your feedbacks will be appreciated!

Meanwhile,?if you liked this article share it or?subscribe?to my newsletter?about?Home Assistant?to read previous episodes and still up to date on latest news.

Gerard Doorman

Director and lead consultant at Pomacon AS

10 个月

Been searching for a while to solve this problem and this did just that, thanks!

要查看或添加评论,请登录

社区洞察

其他会员也浏览了