[SOLVED] Cannot use a variable for set_value action value in automation

Hello! Newbie here. I’m having trouble setting a value using a variable in my automation action. When I try to save the automation, I get an error telling me the value must be a float. The variable I’m using is a float, and I’ve also tried casting it to a float but still no dice. If I change the variable to a number (10), the action saves fine.
Here is the action - it’s the set_value at the last line that is failing:

if:
  - condition: numeric_state
    entity_id: sensor.smart_meter_63a_1_real_power
    below: -1200
  - type: is_not_charging
    condition: device
    device_id: 85a894e59c8559dac336b25d753dfac0
    entity_id: 3264ce2c3949ef1d79d0ea6d58cd44c0
    domain: binary_sensor
    enabled: true
then:
  - service: notify.mobile_app_iphone_90
    metadata: {}
    data:
      message: >-
        Power at {{power}}W - Conditions right to turn charging on at
        {{actual_charge_amps}} amps
  - device_id: 85a894e59c8559dac336b25d753dfac0
    domain: number
    entity_id: e4e74dd7b5bdd8793792217d6b96c3ce
    type: set_value
    value: 100
  - device_id: 85a894e59c8559dac336b25d753dfac0
    domain: number
    entity_id: 7647abf7e5af1e9f98ef63f2700e1314
    type: set_value
    value: {{ actual_charge_amps | float }}

Any help much appreciated!

Device actions do not support templates. Use the number.set_value service instead. Have a read of this: Why and how to avoid device_ids in automations and scripts

1 Like

Thank you! That is the missing piece of documentation I have been searching for.

1 Like