artstam
(Artstam)
November 28, 2023, 8:22am
1
I’m new to homeassistant and been strugling to set a value for a sensor in an automation. But nothing works. Can someone help?
In configuration.yaml
template:
sensor:
name: test_sensor
unique_id: test_sensor
state: >-
{{ states(‘sensor.p1p2_056_s1_compressor_onoff’) | int (0) }}
In automation
action:
service: number.set_value
target:
entity_id: sensor.test_sensor
data:
value: “{{ states(‘sensor.elec_verbruik’) | float(0) * 10 }}”
Result: 2023-11-28 09:22:01.840 WARNING (MainThread) [homeassistant.helpers.service] Referenced entities sensor.test_sensor are missing or not currently available
tom_l
November 28, 2023, 8:39am
2
Please see section 11: How to help us help you - or How to ask a good question
You can not set the value of a sensor with the number.set_value service. That only acts on number entities. e.g. number.my_test_number.
Please explain what you are trying to achieve rather than your chosen solution, see https://xyproblem.info/ there is probably a better way.
artstam
(Artstam)
November 28, 2023, 9:00am
3
tx for your answer!
I’m really new to homeassistant and i’m still strugling with the syntax. What i am trying to achieve is very simple. I want a entity which has to change it’s (numeric) value when a trigger (and conditions) are executed.
tom_l
November 28, 2023, 9:03am
4
That is still your chosen solution rather than your problem. However…
One way would be to use an input number and an automation.
Another way would be a triggered template sensor but these do not have conditions so you would have to build that into the state template.
artstam
(Artstam)
November 28, 2023, 9:09am
5
You are absolutely right, but the input number works!