Maybe it is best to describe what you want to achieve rather than “setting an entity” which cannot be the ultimate goal. Most numerical entities are sensors, they cannot be set by users (think of room temperature, etc).
Plus there might be alltogether other approaches to what you want to achieve.
I have a solarpanel integration (Growatt). One of the entities hold the power in watt of the current power generation. When the sun goes down this value should be 0 eventually. But for some reason the value stays between 5 and 8 watt during the night and rises again when sun rises. So the inverter does not sent the correct value when it’s low.
So I wanted to create an automation which triggers when the value of the power generation is below 10 and then set the value to 0.
I don’t use the Growatt integration, or any solar integration for that matter, so take the below advice with a pinch of salt:
I think you’re going about this the wrong way and need to verify whether the integration is reporting the correct wattage all day long, not just when it’s night.
Assuming your panels aren’t actually picking up some stray ambient light and actually producing power thanks to some neighbour’s floodlights, have you verified with a multimeter that what is reported does not match what is actually being produced?
I’m asking this because it could simply be a matter of calibrating your integration or meter. If neither of these options is possible and your integration reports elevated wattage also during the day, then you’ll probably need to create a template to knock down the reported wattage by 5-8w all the time, not just at night.
If this only happens at night, then again, a template sensor should be able to handle this. Unfortunately I suck at templates, so hopefully someone else with more experience will step up to show you how it’s done.
Either way, you can’t use an automation to override a sensor value. At best, it’ll have to trigger constantly on every report until the value is greater than 10w
Yes. The solution would not be to “set” the original sensor, but create a sensor to have the right behavior. That would be a template sensor. The template would copy the value from the inverter when it is ok.
How do you plan to determine when the value should go to 0?
Logger: homeassistant.components.sensor
Bron: helpers/entity_platform.py:676
integratie: Sensor (documentatie, problemen)
Eerst voorgekomen: 14:36:20 (1 gebeurtenis)
Laatst gelogd: 14:36:20
Error adding entity sensor.adjusted_solar_power_oost for domain sensor with platform template
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 689, in state
numerical_value = float(value) # type:ignore[arg-type]
ValueError: could not convert string to float: "states('sensor.dng0a4702r_pv2_power')"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 676, in _async_add_entities
await self._async_add_entity(
entity, False, entity_registry, config_subentry_id
)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 1002, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1380, in add_to_platform_finish
self.async_write_ha_state()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1024, in async_write_ha_state
self._async_write_ha_state()
~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1149, in _async_write_ha_state
self.__async_calculate_state()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1086, in __async_calculate_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1030, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 691, in state
raise ValueError(
...<5 lines>...
) from err
ValueError: Sensor sensor.adjusted_solar_power_oost has device class 'power', state class 'measurement' unit 'W' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'states('sensor.dng0a4702r_pv2_power')' (<class 'str'>)