How to use the numeric value from a sensor in a trigger action?

I have the following automation:

- id: '1683797880762'
  alias: Set Powerwall Backup Reserve
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.powerwall_reserve_soc
  condition:
  - condition: numeric_state
    entity_id: sensor.powerwall_reserve_soc
    above: sensor.jenkins_family_backup_reserve
    below: sensor.jenkins_family_backup_reserve
  action:
  - device_id: 047f9feaa9922170fe12480d93c37aeb
    domain: number
    entity_id: number.jenkins_family_backup_reserve
    type: set_value
    value: 20
  mode: single

The sensor ‘sensor.powerwall_reserve_soc’ is a numeric sensor that provides a value in the range 0 - 100. I want to use its current value in the trigger action instead of the fixed value of ‘20’ (which I put there as a placeholder). I’m sure this ought to be easy but I’m having trouble finding out how to do it.

Can anyone offer me any pointers on how to achieve this?

Your condition doesn’t make sense: how can the state of the reserve SoC be simultaneously above and below the same value? Can you explain what you’re trying to achieve here — when do you want the action to happen?

To answer your actual question, if your number.set_value service accepts a template:

action:
  - service: number.set_value
    data:
      value: "{{ states('sensor.powerwall_reserve_soc')|int(0) }}"
    target:
      entity_id: number.jenkins_family_backup_reserve
1 Like

I wanted to check if the value of ‘sensor.powerwall_reserve_soc’ was different to the current value of ‘sensor.jenkins_family_backup_reserve’. I already figured out that this doesn’t work and have changed it to be a pair of conditions joined by OR. The lack of documentation is quite a handicap; for example I can’t even find if ‘above’ means > or >=. Similarly for ‘below’.

Your suggestion above works perfectly. Many thanks.

> 100 means above 100 so will not be true if value is exactly 100 it needs to be over 100

>= 100 means equal to or above 100 so would be true if value is 100 or above.

HTH

1 Like