shaonianzhentan / node-red-contrib-ha-mqtt

在HomeAssistant中生成MQTT实体
https://github.com/shaonianzhentan/node-red-contrib-ha-mqtt
MIT License
37 stars 19 forks source link

HomeAssistant tries to convert everything coming from a "sensor" node to float #29

Open valueerrorx opened 1 year ago

valueerrorx commented 1 year ago

Right before i updated HA i was able to use a sensor node to send strings like "on" and "off" (or "high" "mid" "low" and other things) to HA and it would display the string right away next to the icon.

now HA tries to convert everything to float and obviously fails to convert "off" to float - therefore it throws an exception and shows "unknown" next to the icons.

is there a way to configure a sensor node so that HA knows it should just display the received value as string instead of converting it? or ith there another way (another node) i could use for this purpose?

thank you for your work! this palette is very helpful

this is where all of this is needed: https://gitlab.com/valueerror/drexel-weiss-node-red-flow

valueerrorx commented 1 year ago

This is the HA error. After the last update to 6.3 it wants to convert it to int not to float. i don't get what's happening here.


Source: components/sensor/__init__.py:585
Integration: MQTT (documentation, issues)
First occurred: 9:20:16 AM (168 occurrences)
Last logged: 10:31:41 AM

Exception raised when updating state of sensor.uhrzeit, topic: 'ha-mqtt/sensor/Uhrzeit/state' with payload: b'10:27:02'
Exception raised when updating state of sensor.anforderung_badheizung, topic: 'ha-mqtt/sensor/Anforderung_Badheizung/state' with payload: b'aus'
Exception raised when updating state of sensor.luftung_betriebsart, topic: 'ha-mqtt/sensor/LU_Betriebsart/state' with payload: b'Automatikbetrieb'
Exception raised when updating state of sensor.status_warmepumpe, topic: 'ha-mqtt/sensor/Status_Waermepumpe/state' with payload: b'W\xc3\xa4rmepumpe aus'
Exception raised when updating state of sensor.uhrzeit, topic: 'ha-mqtt/sensor/Uhrzeit/state' with payload: b'10:31:03'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 581, in state
    numerical_value = int(value)
                      ^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'aus'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/mqtt/models.py", line 270, in process_write_state_requests
    entity.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 654, in _async_write_ha_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 585, in state
    raise ValueError(
ValueError: Sensor sensor.anforderung_badheizung has device class 'None', state class 'None' unit '' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'aus' (<class 'str'>)
shaonianzhentan commented 1 year ago

There are changes in the sensor components of HA

You need to upgrade this plug-in, and then clear the Unit of measurement of the sensor node, The string status can only be used when the Unit of measurement is empty

valueerrorx commented 1 year ago

wow... that was quick :-)

in order to update it i had to ssh to my node-red raspi (there was no update visible in the web-ui)

cd .node-red/
npm update node-red-contrib-ha-mqtt   
sudo reboot

thank you very much - it works like a charm! if you could add a paypal qr code i would love to buy you some drinks ;-)