Input variable from front end and using it in the config

Hi guys,

I’m trying to use the input box component to have the user specify how many minutes a garage door needs to be open before they get an alert.

I can’t seem to figure out how to use that number in an automation to send a notification. I’m trying to use a template: {{ states(‘input_number.garage_alert_1’) | int }}. The config is checking correctly but when reloading hass it fails so I’m pretty sure that I can’t use this format. Here’s what I did:

input_number:                         
  garage_alert_1:               
    name: Garage Alert 1 (mins)                                      
    min: 5                                                            
    max: 120                                                  
    step: 5                                                       
    unit_of_measurement: minutes                                                     
    icon: mdi:timer                                       
    mode: box             

automations:
- alias: Notifications Garage Door is Open for x minutes                                          
  trigger:                                                                                        
    - platform: state                                                                             
      entity_id: binary_sensor.garagedoorswitch_2_3                                               
      to: "on"                                                                                    
      for:                                                                                        
        minutes: {{ states('input_number.garage_alert_1') | int }}                                
  action:                                                                                         
    - service: notify.telegrambotgroup                                                            
      data:                                                                                       
        message: Garage has been open for {{ states('input_number.garage_alert_1') | int }} minutes
        data:                                                        
          keyboard:                                
            - '/Turn_off_alerts, /Close_Garage_Door' 

It looks like the spacing is correct in the trigger, but i’m not sure you can have a jinja in the trigger outside a value_template.

for testing purposes, try switching your trigger to 1 minute instead of the {{}}. If it triggers, then {{}} is not aloud in that field.

Also, you could try putting the {{}} in quotes for minutes. Most 1 line value_templates require quotes. Only multi-line ones can be written without quotes if I remember correctly.

Shouldn’t this be data_template?

1 Like

Didn’t even notice that! nice catch. Pretty sure you’re right.

Thanks for that, changed it to data_template but the main issue is with the minutes in the trigger. I tried what @petro mentioned and tried using single quotes (’) and double quotes (") but no luck.

yeah, best guess is that it doesn’t allow jinja there.

Hmm, i’m wondering if you should just create a timer that starts when you turn on the light.

then use a value_template as a trigger:

trigger:

  • platform: template
    value_template: “{{ is_state(‘binary_sensor.garagedoorswitch_2_3’, ‘on’) and states(‘timer.timerthingy’) > 5*60 }}”

yeah hard coding works

or try this:

trigger:
  - platform: template
    value_template: "{{ is_state('binary_sensor.garagedoorswitch_2_3', 'on') }}"
    for:
      minutes: "{{ states('input_number.garage_alert_1') | int }}"

doesn’t like ‘for’
2018-02-16 14:35:01 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: [for] is an invalid option for [automation]. Check: automation->trigger->0->for. (See /config/configuration.yaml, line 195). Please check the docs at https://home-assistant.io/components/automation/

Welp. Looks like this isn’t possible unless some super guru happens upon this thread. You may want to look into the timer functionality and build off that instead of using the for.

Thanks for your help. I haven’t played with the timer, I’ll see if there is a way to set it via the front end.