Template in Script results in "expected str for dictionary value @ data['value']. Got None"

I’m working on a script that has the following service call:

service: fully_kiosk.set_config
alias: Reset The Screen Timeout
data:
  key: timeToScreenOffV2
  value: "{{ original_screen_timeout }}"
target:
  device_id: "{{ fully_kiosk_device }}"

Where original_screen_timeout is a variable that is set earlier in the script. When I run my script I get the error:

Failed to call service script.myscript. expected str for dictionary value @ data['value']. Got None

After some fiddling about it seems that the value needs to be a string in quotes but for some reason no mater what I do the script will call the service like:

value: 60

Which doesn’t work. If I call the service by hand with the same value I get the same error. I’ve tried wrapping it in quotes and that stopped the error but the service didn’t run correctly because the service is called with:

value: '"60"'

Is there any way to get around this?

I don’t think that is your issue. The “Got none” in the error means it is not getting anything.

How are you calling the script and passing the variables?

There are two ways.

  1. Script as a service:
  action:
    service: script.notify_pushover
    data:
      title: "State change"
      message: "The light is on!"
  1. Using the script.turn_on service:
  action:
    service: script.turn_on
    target:
      entity_id: script.notify_pushover
    data:
      variables:
        title: "State change"
        message: "The light is on!"

Note the extra variable key requirement if using the script.turn_on service.

See: https://www.home-assistant.io/integrations/script/#passing-variables-to-scripts

Right now I’m calling the script via the developer tools and I’m not passing that variable to the script directly, it’s read a little further up in the script:

variables:
  original_screen_timeout: "{{ state_attr(variable_sensor, attribute_original_timeout) }}"

Variables all the way down. But when I look at the trace for my script it’s getting the correct value:

params:
  domain: fully_kiosk
  service: set_config
  service_data:
    key: timeToScreenOffV2
    value: 60
    device_id:
      - fa2c8f43e42a1041bd8950782e7e9517
  target:
    device_id:
      - fa2c8f43e42a1041bd8950782e7e9517
running_script: false

If I go to the developer tools and try to call the set_config service the same way it throws the same error:

But if I put the value in quotes (which the UI does as well) it works. It’s very weird.

I was looking at the source for the Full Kiosk integration and I wonder if part of the issue is this line that validates the value as a bool or string. It seems like it would work if that were expanded to include numeric values then cast them to strings before making the actual call (or something like that, my Python is trash lol)

Looks like this was an issue where I had suspected. It required a few more changes than expected but it seems to be working now and I’ve created a PR for the fix