Home assistnat doesn’t allow updating sensors from Node-red. Recommended way is to create a MQTT sensor and send values from Node-red. allowing sensors to be updated directly by Node-red will save a lot of headache and give full flexibility.
francisp
(Francis)
October 1, 2023, 4:16pm
2
Can’t Node Red do a post call ?
WallyR
(Wally)
October 1, 2023, 7:39pm
3
HA only allow the sensor’s integration to update its value.
But integrations often have service calls to set some sensor values.
I use the set_state.py script on node red. I even opened a feature request to see if the function is added.
opened 08:20PM - 10 Aug 23 UTC
closed 01:48AM - 09 Dec 23 UTC
Stale
zachowj Thank you for your work.
I use NR to request the status of my alarm a… nd create all the sensors.
But if for some reason the NR loses the connection with the alarm, the sensors keep the last state received.
I use the script below to change the sensors to "unavailable", but it would be nice if NR had this function natively.
```
"""Set the state or other attributes for the specified entity."""
# ========================================================================================
# python_scripts/set_state.py
# modified from -
# https://community.home-assistant.io/t/how-to-manually-set-state-value-of-sensor/43975/37
# ========================================================================================
# ----------------------------------------------------------------------------------------
# Set the state or other attributes for the specified entity.
# Updates from @xannor so that a new entity can be created if it does not exist.
# ----------------------------------------------------------------------------------------
inputEntity = data.get("entity_id")
if inputEntity is None:
logger.warning("===== entity_id is required if you want to set something.")
else:
inputStateObject = hass.states.get(inputEntity)
if inputStateObject is None and not data.get("allow_create"):
logger.warning("===== unknown entity_id: %s", inputEntity)
else:
if not inputStateObject is None:
inputState = inputStateObject.state
inputAttributesObject = inputStateObject.attributes.copy()
else:
inputAttributesObject = {}
for item in data:
newAttribute = data.get(item)
logger.debug("===== item = {0}; value = {1}".format(item, newAttribute))
if item == "entity_id":
continue # already handled
elif item == "allow_create":
continue # already handled
elif item == "state":
inputState = newAttribute
else:
inputAttributesObject[item] = newAttribute
hass.states.set(inputEntity, inputState, inputAttributesObject)
```
This is the thread where I got the script.
Is it possible to manually set the state of a binary sensor or any sensor as part of an action in automation, i.e.
trigger:
platform: homeassistant
event: start
action:
"Set binary_sensor.sensor1 to state "ON""
"Set sensor.sensor2 to value "12.5""
I understand that currently HA only allows sensor integration to update it’s value. I think I am asking why this restriction ? why not allow anyone to update the values. There are lot of times, you need the value to be overridden or set manually.
tom_l
October 2, 2023, 12:00am
7
Sensors update automatically. If you want something to be updated manually use an input_* helper.
is input helper drop in replacement for sensor ? for example, if i have a nmap presence sensor which updates from router periodically. in some cases, I would like to force update the sensor with data obtained from other sensors (arp udp packets).
I know there are roundabout way to create a template sensor etc to get around current limitations. But as of now, not only i can’t update the value, I can’t even force the sensor to update outside of it’s normal poll period.
tom_l
October 2, 2023, 1:42pm
9
Does the homeassistant.update_entity
service not work?
nope (atleast not for nmap integration). probably dependent on integration.