#cast it in the variable statement

1 messages · Page 1 of 1 (latest)

compact geyser
#
variables:
    motion_sensor: !input motion_sensor
    presence_sensor: !input presence_sensor
    complimenting_light_mode: !input complimenting_light_mode
    seconds_delay: !input seconds_delay | float(180)
slate gull
#

i see. it's neat that you can pipe and use template vars when setting vars.

same issue when doing that though expected float for dictionary value @ data['for']['seconds']. Got None

i believe the resulting value from the template isn't being set into the seconds key for some reason

compact geyser
#

based on the other part of the code, default should be(180)

slate gull
#

i'd expect it to say something like Got Text instead of Got None if my template was setting the wrong type

compact geyser
#

Did you take that broken code out of the for statement?

slate gull
#
      hours: 0
      minutes: 0
      seconds: >
        {% if is_state('binary_sensor.night_mode', 'on') %}
          180
        {% else %}
          {{ seconds_delay }}
        {% endif %}``` yeah
compact geyser
#

Put an actual number in the template instead of seconds_delay to test

slate gull
#

actually, looks like it doesnt like that | float (2) syntax.

error: Invalid blueprint: Missing input definition for seconds_delay | float(2) (See /config/configuration.yaml, line 9).

#
    seconds_delay: !input seconds_delay | float(2)```
compact geyser
#

Here is how they do it in the docs...

automation:
  trigger:
    - platform: numeric_state
      entity_id:
        - sensor.temperature_1
        - sensor.temperature_2
      above: 80
      for:
        minutes: "{{ states('input_number.high_temp_min')|int }}"
        seconds: "{{ states('input_number.high_temp_sec')|int }}"
#

except not you need a default, so add (180)after float.

slate gull
#

i probably need to create a single template line that handles the if conditional, the 180, and the seconds_delay.

compact geyser
#

I pick 180 as default because that is your dark default, if number input is broken it wil all still work the same

slate gull
#

seems like part of the problem is the syntax:

templating logic on next lines```
#

im not sure how that is processed differently from same-line template like in that docs example

compact geyser
#

yesthat could be also, but the variable is I think going to give you text.

slate gull
#

it miiight be - though the input is using a numbers selector

compact geyser
#

just put it in a line. change the newlines into spaces.

#

play with it in the developer screen template tester

slate gull
#

even a basic seconds: "{{ seconds_delay | float(2) }}" is giving the Expected float ... Got none error despite being a number in the dev template tester

#

('seconds_delay', 360) passed into the blueprint, expected float for dictionary value @ data['for']['seconds']. Got None error despite something simple like seconds: "{{ seconds_delay|int }}" and variables: seconds_delay: !input seconds_delay strange.

compact geyser
#

You must be running into limited templates. Look that up, memory it pinging me something about that.

slate gull
#

hm yeah, definitely seems likely.
official docs say these arent supported in limited templates:

  • states (strange that you saw it being used in the official docs trigger template)
  • attributes (state_attr)
  • groups (expand)
  • device_attr
  • is_device_attr
  • time (now and utcnow)
  • distance

so is_state wont work, dang.

doesn't explain exactly why {{ seconds_delay }} doesn't work - though i'd lean towards it being not documented that blueprint variables are not supported in limited templates.

#

i need to rethink the blueprint then, thanks for the help

compact geyser
slate gull
#

yeah thats exactly what i ended up doing, works nicely