Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 108134

How to setup automation with helper as number variable used in condition and actions

$
0
0

I’m still very new to HA, but I’ve been banging my head against a wall for what I feel is a stupid simple automation setup. I’m trying to utilize a variable (I’m familiar enough in Python & Jinja) and effectively just want to set some basic value which I can subsequently utilize in the automation: both in the conditions and in the subsequent actions.

My end goal is to have an automation run at a set time every day which checks whether or not any of my printer’s ink is below a certain percentage (the variable) and subsequently send a notification if it is.

How I have this setup with the functional and non functional components:

  • Working: I have created an input_number Helper with my desired ink threshold (real: 11.0)
  • Working: I have notification actions which successfully sends a message with the desired threshold variable included
  • Not Working: conditions which correctly only cause the automation to trigger actions if below the set threshold

What I’ve tried:

  • Using jinja to populate the below with the helper value. This produces a dictionary error when I try to save the automation saying it’s expecting a float value
  • Using the native UI to reference the helper value. Every time I subsequently complete a test run my actions are triggered to send a notification even though none of my printer’s ink sensors actually report a percentage below the set helper value… this YAML I’ve included below:
alias: "PRINTER: Notify on low printer toner"
description: If below 'input_number.printer_ink_min_percent', notify
trigger:
  - platform: time
    at: "10:00:00"
condition:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.hp_officejet_pro_6970_black_ink
        below: input_number.printer_ink_min_percent
      - condition: numeric_state
        entity_id: sensor.hp_officejet_pro_6970_cyan_ink
        below: input_number.printer_ink_min_percent
      - condition: numeric_state
        entity_id: sensor.hp_officejet_pro_6970_magenta_ink
        below: input_number.printer_ink_min_percent
      - condition: numeric_state
        entity_id: sensor.hp_officejet_pro_6970_yellow_ink
        below: input_number.printer_ink_min_percent
action:
  - service: notify.mobile_app_pixel_8_pro
    data:
      message: >-
        One or more toner cartridges are below {{ states('input_number.printer_ink_min_percent')|round }}%
      title: Printer Toner Low
  - service: notify.persistent_notification
    metadata: {}
    data:
      title: Printer Toner Low
      message: >-
        One or more toner cartridges are below {{ states('input_number.printer_ink_min_percent')|round }}%
mode: single

What am I doing wrong or missing to achieve my desired goal?

Thanks in advance!

6 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 108134

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>