Set entity value with template

Hi,

I have a danfoss termostat which expose an entity number.thermostat_salon_external_measured_room_sensor which i want to update with an external sensor

So i did an automation but there is no thermostat service to set this so I’m using the action device and use sub action to set this value.
now i put an harcoded value, it works but if i try to use a template it keep complaining that it’s not a float value

device_id: 26657ff769f11ef36986b51b3b024ca0
domain: number
entity_id: 9043d142bb3a5be63f851d8046f14ee2
type: set_value
value: "{{ states('sensor.sonde_salon_temperature') | float(0) }}"

Now i did try this template in the development tools and it’s working
So are template not supported here ? how can i set this number.thermostat_salon_external_measured_room_sensor ?

i have managed to do what I wanted by sending a mqqt message, but still it should be possible to change the entity value with a template

Device actions do not support templates, but it is possible. Use the number set value service instead: https://www.home-assistant.io/integrations/number/#services

- service: number.set_value
  target:
    entity_id: number.thermostat_salon_external_measured_room_sensor
  data:
    value:: "{{ states('sensor.sonde_salon_temperature') | float(0) }}"

You should stop using device triggers, conditions and actions. See: Why and how to avoid device_ids in automations and scripts

1 Like

I did try this, but i had an error, something like unsupported entity
Though this one was only for input_number as the visual editor only let you choose them

And i think i use device nowhere in my automation, always service but thanks for the link

Try again and post the exact error text.

ha my bad i was not calling the right service, it was input_number.set_value

btw number can’t be a float value in HA ?

each time it’s set to a float value, something trigger a round and value change

1 Like

Number does support float values. However just like input_number they can have a defined precision or “step” attribute that you can not exceed. For example step: 0.5 gives 0.0, 0.5, 1.0, 1.5… as allowed values, step: 1 gives 0.0, 1.0, 2.0, 3.0… as allowed values.

thanks for the help

Hi Tom,

Is it possible to do this for a state device rather than number?

Eg: I want to set an Alarm panel (States arm_away, arm_home etc) to a value I derive from a SQL query that returns one of the those states.

Currently I have to do a long choose, eg:

  - choose:
      - conditions:
          - condition: state
            entity_id: sensor.aqara_m2_sql_last_state
            attribute: state
            state: armed_away
        sequence:
          - service: alarm_control_panel.alarm_arm_away
            target:
              entity_id:
                - alarm_control_panel.aqara_hub_m2_2237_security_system
            data: {}
      - conditions:
          - condition: state
            entity_id: sensor.aqara_m2_sql_last_state
            attribute: state
            state: armed_night
        sequence:
          - service: alarm_control_panel.alarm_arm_night
            target:
              entity_id:
                - alarm_control_panel.aqara_hub_m2_2237_security_system
            data: {}
      - conditions:
          - condition: state
            entity_id: sensor.aqara_m2_sql_last_state
            attribute: state
            state: armed_home
        sequence:
          - service: alarm_control_panel.alarm_arm_home
            target:
              entity_id:
                - alarm_control_panel.aqara_hub_m2_2237_security_system
            data: {}
      - conditions:
          - condition: state
            entity_id: sensor.aqara_m2_sql_last_state
            attribute: state
            state: disarmed
        sequence:
          - service: alarm_control_panel.alarm_disarm
            target:
              entity_id:
                - alarm_control_panel.aqara_hub_m2_2237_security_system
            data: {}

It would be nice to just set alarm_control_panel.state=sensor.aqara_m2_sql_last_state somehow

JC.

Not sure what that means, but you can template the service call.

Your first three conditions can be reduced to this assuming there are no other 'armed_*' states not listed, and I’ve left your 'disarmed' one on the end:

- choose:
      - conditions:
          - "{{ 'armed_' in states('sensor.aqara_m2_sql_last_state') }}"
        sequence:
          - service: alarm_control_panel.alarm_{{ states('sensor.aqara_m2_sql_last_state')|replace('armed','arm') }}
            target:
              entity_id:
                - alarm_control_panel.aqara_hub_m2_2237_security_system
      - conditions:
          - condition: state
            entity_id: sensor.aqara_m2_sql_last_state
            attribute: state
            state: disarmed

I’m using template condition shorthand notation there.

1 Like

Ahhh, very clever Troon,

Never thought of templating text replacement like that,

I like it, I missed the last lines for disarmed in my original post (edited now) so your solution works for that as well (removed_ in 1st choose condition it include disarmed as well)

choose:
    - conditions:
        - "{{ 'armed' in states('sensor.aqara_m2_sql_last_state') }}"
      sequence:
        - service: alarm_control_panel.alarm_{{ states('sensor.aqara_m2_sql_last_state')|replace('armed','arm') }}
          target:
            entity_id:
              - alarm_control_panel.aqara_hub_m2_2237_security_system

Nice, and thanks.

JC.

1 Like