Using a variable to set device value

Hello There, I´m configuring wallbox EV charger to dynamically set the max charge to use based on available Amp at home. in order to do that, first I need to know how much available amp do I have, but this is something already got in a sensor called sendor.carga_wallbox.

what I´m missing now is in an automation to set this sensor value to wallbox max charge, I created this automation:
</
alias: Wallbox a 17
description: “”
trigger:

  • platform: numeric_state
    entity_id:
    • sensor.acometida_amp
      above: 20
      condition:
      action:
  • device_id: 91bc1fbd644674d94abcfc589634d9be
    domain: number
    entity_id: b6564c42c5fba3711507b469621ed3d8
    type: set_value
    value: {{ sensor.carga_wallbox }}
    mode: single
    />

When sensor Acometida is below 20 I want to set the value for this entity which is sensor.wallbox_commander_2_sn_755800_corriente_de_carga_maxima

But error receive is this one:
Message malformed: expected float for dictionary value @ data[‘value’]

Anybody having such or similar experience¿

There are a few issues:

  1. The template is not surrounded in quotes.
  2. There is no function call to tell it which value you want from the sensor’s state object.
  3. Without quotes around it sensor.carga_wallbox is treated as a variable, which you have not assigned a value to.
  4. You are trying to use a template where it isn’t supported. Use an entity action, not a Device action.

What you want is:

action: number.set_value
target:
  entity_id: b6564c42c5fba3711507b469621ed3d8
data:
  value: "{{ states('sensor.carga_wallbox') }}"

Device Actions don’t support templates. Use the number.set_value action.

 - action: number.set_value
   target:
     entity_id: number.your_number_entity
   data:
     value: "{{ states('sensor.carga_wallbox') }}"

Hello, having this gaves me the same error, sorry

Not sure if I understood you, shall I have this inside the automation, or should I do this at a sensor?

You created an automation containing one Device Action.

A Device Action doesn’t support templates. That’s why you are getting an error message.

Replace the Device Action with what I posted above. The number.set_value action does support templates.

then, I have now this:

alias: Wallbox a 17
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.acometida_amp
    above: 20
condition: []
  - action: number.set_value
    target:
      entity_id:  number.wallbox_commander_2_sn_XXXXXX_corriente_de_carga_maxima
    data:
      value: "{{ states('sensor.carga_wallbox') }}"

Getting this error
Message malformed: Unable to determine action @ data[‘action’][0]

Also tried with entity number, as showed here, but same error

alias: Wallbox a 17
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.acometida_amp
    above: 20
condition: []
  - action: number.set_value
    target:
      entity_id: number.b6564c42c5fba3711507b469621ed3d8
    data:
      value: "{{ states('sensor.carga_wallbox') }}"

You’re missing the action: header, perhaps confused by the recent renaming of service to action. Fixed below. Maybe use the UI if you’re not secure in YAML.

alias: Wallbox a 17
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.acometida_amp
    above: 20
condition: []
action:
  - action: number.set_value
    target:
      entity_id:  number.wallbox_commander_2_sn_XXXXXX_corriente_de_carga_maxima
    data:
      value: "{{ states('sensor.carga_wallbox') }}"
1 Like

The example above assumes a recent version of Home Assistant. For older versions, replace:

  - action: number.set_value

with:

  - service: number.set_value
1 Like

That´s the option worked, I will test tonight!!! Finger Cross

Thanks, highly appreciated

As Troon explained, the automation you created is malformed and is missing an action: key.

If you are attempting to create the automation in YAML, I recommend you use the Automation Editor in Visual mode until you become more familiar with YAML.

The main mistake you made in your original automation (the example in your first post) is that you attempted to use a template with a Device Action which doesn’t support templates.

The solution is to use the number.set_value action instead of the Device Action. It supports templates.

The second problem was that the template you designed was incorrect. If you want to get an entity’s state value, you must use the states() function.

The last mistake was omitting the action: key from the automation.