Prompting for variable to pass to a script every time

Hi all. I have Home Assistant setup and configured with an Alarm system that utilizes Envisalink.

I can call a function that would allow me to enter “1234” into the alarm panel by utilizing the envisalink_alarm_keypress function and then manually specifying a numeric keypress in the script to pass on to the “keypress” parameter. However, this 1234 is a static value that would be hard coded in the backend configuration.yaml.

Is there anyway that i can create a script or function that every time that I activate the script, it will ask for a number string to pass onto to the “keypress” parameter? As a bonus, if when I hit activate it gives me a number pad that would be ideal, but if not, simply a text box that would take that value and pass is to the variable in the script would be fine too.

This can be done relatively easily in the service dev tool but really would prefer that it be a permenant button on the view for anyone to use.

You should be able to rig that with an input_text. Enter a value into the input (you can configure the input to password mode to obscure input). Grab the input’s value in your script’s service call. You could then have your service clear the value after it runs.

I can see that potentially working but not sure exactly how to make it work.

Here’s my basic script:

alarm_test:
 sequence:
  - service: alarm_control_panel.envisalink_alarm_keypress
    data:
     entity_id: alarm_control_panel.alarm
     keypress: 123456

The field of keypress of “123456” is what I want to be prompted for each time. Is that possible?

alarm_test:
  sequence:
    - service: alarm_control_panel.envisalink_alarm_keypress
      data_template:
        entity_id: alarm_control_panel.alarm
        keypress: "{{ states('input_text.WHATEVER') }}"

Also - with an Envisalink, wouldn’t you be better off calling alarm_control_panel.alarm_disarm? It accepts a code value.

Unfortunatley that does not work. It isn’t able to call the text.

In configuration I have:

input_text:
  text1:
    initial: 123456

And to answer @ih8gates, yea, for a simple disarm this is fine, since it grabs the code from the configuration. I am trying to use HA to basically emulate a full number keypad, but it is not working like I would have hoped. Too many issues along the way to make it happen.

alarm_disarm is a service. You can call it with a code value not stored in your YAML.

  action:
    service: alarm_control_panel.alarm_disarm
    data:  
      entity_id: alarm_control_panel.house
      code: 9999
1 Like

Right. The ultimate goal here is to be able to activate a script, and when it activates, prompt me for a code string to enter into the alarm panel. I don’t think that is supported though, am I correct in that?

Probably not, but you can have the entry field on the same group card as the script. Which really isn’t that different. You can alternately do a persistent notification as an error message if someone triggers the script without valuing the password field.

Ok, so let’s say that I do what you suggested. Basically enter a number, then activate the script. How would that script look?

I couldn’t get this to work even with a static initial value of a text field.

In configuration.yaml:

input_text:
  text1:
    initial: 123456

then for the scripts.yaml:

alarm_test:
  sequence:
   - service: alarm_control_panel.envisalink_alarm_keypress
     data_template:
      entity_id: alarm_control_panel.alarm
      keypress: "{{ states('input_text.text1') }}"

But activating that doesn’t seem to take the entry of 123456 for the keypress. Wonder if it has to do with the quotes and the fact that its actually a number and not alpha. It WILL work if i manually enter 123456 in the script after keypress, but it doesnt seem to like the text input variable, so I must be doing something wrong.

I’m not sure what that sentence means. Do you mean that you tried hard-coding the password into the script’s YAML?

You might try casting the value as a string to make sure that’s not the issue.

keypress: "{{ states('input_text.text1') | string }}"

But I kinda doubt that’s the issue.

That did not work either.

ANd yes, i made that about as clear as mud before. What I meant is if i run the script like this, with a keypress hardcoded in the yaml it DOES send the keypress as anticipated:

alarm_test:
  sequence:
   - service: alarm_control_panel.envisalink_alarm_keypress
     data_template:
      entity_id: alarm_control_panel.alarm
      keypress: 123456

So there’s something going on where it simply does not want to accept the variable here.

Here’s what I see in the log file when I call the script with the modification that you recommended.

2018-04-23 15:47:08 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=alarm_control_panel, service=envisalink_alarm_keypress, service_data=entity_id=alarm_control_panel.alarm, keypress={{ states(‘input_text.text1’) | string }}, service_call_id=140680446821992-226>

Looks like keypress isn’t receiving the templated value, it’s receiving the template. You’re sure you’re using data_template:, not just template:?

Have you also tested with alarm_control_panel.alarm_disarm? Note that it wants “code” instead of “keypress”.

aha! I had data instead of data_template. I was going back and forth between them as I was trying things out. So now that I changed this to be data_template it worked as intended.

Now, if only there would be a way to display a numberpad instead of a text box… :slight_smile:

Thank you for the assistance.

You could probably make one using custom panels… each keypress would concatenate a # value to your input_text. But that’s not something I’ve tried.

Trying to do the same thing can you share you final script?

This never really worked well, since it was really kludgy to try to use so i basically abondoned this.

I came across this the other day which I am going to try this week, and think this possibly has potential to do the same thing that I was originally trying to do.