Using parameters that are passed into a script that are floats

Hi I have created a script that takes in a parameter and calls another command.

 device_id: baa529bdac31ba1a8ed11781f2d98e2f
    domain: number
    entity_id: number.zigbeealarm_duration
    type: set_value
    value: "{{duration}}"

The variable is obviously a float as when I attempt to save this I get an error stating “Message malformed: expected float for dictionary value @ data[‘value’]”

I have attempted various solutions in the forum but non of them appear to work. The one that appears to be the most popular is to use “{{ duration | float }}” but I get the same error message.

Any help would be appreciated.

Thanks

Device actions don’t support templates. Use a normal Action (call a service).

Also, please format your code correctly for the forum with the </> button.

  - action: number.set_value
    target:
      entity_id: number.zigbeealarm_duration
    data:
      value: "{{ duration }}"
1 Like

Thank you.

Hi,

I have tried to convert the rest of my script using normal actions but it doesnt appear to be setting the values on the device. When I run the new script it plays but does not change the volume, sound etc.

The original script was

alias: Activate Kitchen Alarm v2 WIP
sequence:
  - type: turn_off
    device_id: baa529bdac31ba1a8ed11781f2d98e2f
    entity_id: switch.zigbeealarm_alarm
    domain: switch
  - action: number.set_value
    target:
      device_id: baa529bdac31ba1a8ed11781f2d98e2f
      entity_id: select.zigbeealarm_melody
    data:
      value: "4"
  - action: number.set_value
    target:
      device_id: baa529bdac31ba1a8ed11781f2d98e2f
      entity_id: select.zigbeealarm_volume
    data:
      value: 5
  - action: number.set_value
    target:
      device_id: baa529bdac31ba1a8ed11781f2d98e2f
      entity_id: number.zigbeealarm_duration
    data:
      value: 5
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 5
  - type: turn_on
    device_id: baa529bdac31ba1a8ed11781f2d98e2f
    entity_id: switch.zigbeealarm_alarm
    domain: switch
mode: single
description: ""

The script above works fine but it doesnt lend itself to passing in parameters as Troon called out about. So I tried converting it to this.

alias: Activate Kitchen Alarm v2 WIP2
sequence:
  - type: turn_off
    device_id: baa529bdac31ba1a8ed11781f2d98e2f
    entity_id: switch.zigbeealarm_alarm
    domain: switch
  - action: number.set_value
    target:
      device_id: baa529bdac31ba1a8ed11781f2d98e2f
      entity_id: select.zigbeealarm_melody
    data:
      value: "4"
  - action: number.set_value
    target:
      device_id: baa529bdac31ba1a8ed11781f2d98e2f
      entity_id: select.zigbeealarm_volume
    data:
      value: 5
  - action: number.set_value
    target:
      device_id: baa529bdac31ba1a8ed11781f2d98e2f
      entity_id: number.zigbeealarm_duration
    data:
      value: 5
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 5
  - type: turn_on
    device_id: baa529bdac31ba1a8ed11781f2d98e2f
    entity_id: switch.zigbeealarm_alarm
    domain: switch

The alarm plays but ignores all of the settings such as duration, volume and melody. I think I must have missed something somewhere. Any help would be appreciated.

Thanks

Steve

Your code is… a mess. Feels like you need to start reading the documentation, not just throw stuff at the wall to see what sticks.

Replace the first and last action with switch.turn_off / switch.turn_on actions.

You should not be using a device id with any of these actions. If using a device id, the action will be attempted on every entity belonging to that device.

On two of the actions you are attempting to use a number.set_value on a select entity. Only actions prefixed with select. can operate on a select entity. In one of them you aren’t even feeding in a number, but a string.

Something like this, but you need to replace the intended values for your selects with the exact text of the desired options (without brackets around them):

- action: switch.turn_off
  target:
    entity_id: switch.zigbeealarm_alarm
- action: select.select_option
  target:
    entity_id: select.zigbeealarm_melody
  data:
    option: [Exact option text, without brackets!]
- action: select.select_option
  target:
    entity_id: select.zigbeealarm_volume
  data:
    option: [Exact option text, without brackets!]
- action: number.set_value
  target:
    entity_id: number.zigbeealarm_duration
  data:
    value: 5
- delay:
    milliseconds: 5
- action: switch.turn_on
  target:
    entity_id: switch.zigbeealarm_alarm
1 Like