HA Node-RED Integration - Strings, everywhere STRINGS!

Right u r @Hellis81 . I also started to realize that the extensive usage of function nodes makes it often hard to understand what´s actually going on in there :grimacing: I have to admit I still have to find a good balance of using function nodes combined with other elements properly

Yes that is a big disadvantage with function nodes.
One way that I have found out to debug is to write debug messages in the function node to the message, that way you can see where the code has been.

Started doing that as well - Really helpful I have to say :smile:

Still enjoying the talk…
The NodeRed flow node-red-contrib-home-assistant-websocket (node) - Node-RED is using the REST API or the websocket to talk to HA.
I checked manually using the API to request a sensor whose state is a number. In the JSON response is given back as a string… The NodeRed is not the “culprit”. It is the API!

Example accessing my pihole sensor:

    {
        "entity_id": "sensor.pi_hole_dns_queries_today",
        "state": "180415",
        "attributes": {
            "domains_blocked": 94124,
            "unit_of_measurement": "queries",
            "friendly_name": "Pi-Hole DNS Queries Today",
            "icon": "mdi:comment-question-outline"
        },
        "last_changed": "2021-07-22T17:36:03.008997+00:00",
        "last_updated": "2021-07-22T17:36:03.008997+00:00",
        "context": {
            "id": "84b480dd2c62e4c591e95ae179269308",
            "parent_id": null,
            "user_id": null
        }

Look at the “state”!
Funnily enough the number attribute is back as a number.

So, the title of your post should be “HA REST API - all States as Strings!” :grinning:

Don‘t worry, @Hellis81 can show u how to turn it into a float :joy:

Here’s an example:

[{"id":"5d779a64.c10c14","type":"delay","z":"94bc1df0.962d9","name":"","pauseType":"delay","timeout":"4","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":840,"y":3020,"wires":[["7339f1f1.0650b"]]},{"id":"e490231e.ef85e","type":"inject","z":"94bc1df0.962d9","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"123","payloadType":"str","x":670,"y":2980,"wires":[["9b850d6b.479c9","c5b2f264.58f46","5d779a64.c10c14"]]},{"id":"7339f1f1.0650b","type":"function","z":"94bc1df0.962d9","name":"","func":"msg.payload = msg.payload*1;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":990,"y":3020,"wires":[["9b850d6b.479c9"]]},{"id":"9b850d6b.479c9","type":"debug","z":"94bc1df0.962d9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1130,"y":2980,"wires":[]},{"id":"c5b2f264.58f46","type":"delay","z":"94bc1df0.962d9","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":840,"y":2920,"wires":[["6f955220.9f069c"]]},{"id":"6f955220.9f069c","type":"function","z":"94bc1df0.962d9","name":"","func":"msg.payload = parseFloat(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":980,"y":2920,"wires":[["9b850d6b.479c9"]]}]

:joy:

If we use the NR palette, you don’t need that! :face_with_hand_over_mouth: