zachowj / hass-node-red

Companion Component for node-red-contrib-home-assistant-websocket to help integrate Node-RED with Home Assistant Core
MIT License
460 stars 182 forks source link

HA warning for sensor class 'time stamp' (will be unsupported for HA >= 2022.2) #103

Closed KNXBroker closed 2 years ago

KNXBroker commented 2 years ago

Version of the custom_component

Node-RED Current version: 10.3.0 Node-RED Companion: 1.0.5 Home Assistant: 2021.12.8

Configuration

[{"id":"e72137461d4aa285","type":"inject","z":"a04618a4.e5c6d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":680,"wires":[["a68949d148829fec"]]},{"id":"aff1f15236b669cb","type":"ha-entity","z":"a04618a4.e5c6d8","name":"testtime","server":"55c2f3c6.2dce0c","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"testtime"},{"property":"device_class","value":"timestamp"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":680,"y":680,"wires":[[]]},{"id":"a68949d148829fec","type":"moment","z":"a04618a4.e5c6d8","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Berlin","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"C","output":"","outputType":"msg","outTz":"Europe/Berlin","x":460,"y":680,"wires":[["aff1f15236b669cb"]]},{"id":"55c2f3c6.2dce0c","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

Describe the bug

I'm using node red to convert unix time stamps to Home Assistant Format (ISO8601).

Since HA 2021.12 there is the following warning in Home Assistant:

Logger: homeassistant.components.sensor
Source: components/sensor/__init__.py:376
Integration: Sensor (documentation, issues)
First occurred: 21:33:44 (2 occurrences)
Last logged: 21:37:01

sensor.testtime is providing a string for its state, while the device class is 'timestamp', this is not valid and will be unsupported from Home Assistant 2022.2. Please report it to the custom component author.

May I ask you to add respective type conversion? Thank you

Debug log

See description

zachowj commented 2 years ago

If you're using the current time for your date string you can forgo the moment node use JSONata as the state set to $now()

KNXBroker commented 2 years ago

Thank you @zachowj