Problem z encją

Witam zrobiłem sobie sprawdzanie baterii w telefonie. Mam tylko jedno pytanie skąd w powiadomieniu jest “undefine” ?
ddd

Ja mam tak rozwiązane dla kilku urządzeń.
I kończę powiadomieniami tymi od Artura.

[{"id":"1a5e6365.04657d","type":"server-state-changed","z":"b1f8b0b1.8198b","name":"Andrzej","server":"e623594f.2c1a08","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.gm1913_poziom_baterii","entityidfiltertype":"exact","outputinitially":true,"state_type":"num","haltifstate":"10","halt_if_type":"num","halt_if_compare":"lt","outputs":2,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":90,"y":1970,"wires":[["73ad79b5ce4235e2"],[]]},{"id":"bddb9dd2.25504","type":"change","z":"b1f8b0b1.8198b","name":"Andrzej","rules":[{"t":"set","p":"person","pt":"msg","to":"Andrzej","tot":"str"},{"t":"set","p":"poziom_baterii","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":1970,"wires":[["4b144cdd.6ebd24"]]},{"id":"e1cedfa.587432","type":"function","z":"b1f8b0b1.8198b","name":"Bateria","func":"msg.wiadomosc =\n{\n    \"temat\":\"Bateria\",\n    \"tresc\":msg.person+\" podłącz telefon do ładowania. Aktualny stan to \"+msg.poziom_baterii+\"%\",\n    \"typ\":\"info\",\n    \"kto\": \"andrzej\"\n    \n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":980,"y":1970,"wires":[["61e91d1c.e001c4"]]},{"id":"4b144cdd.6ebd24","type":"api-current-state","z":"b1f8b0b1.8198b","name":"Czy się ładuje","server":"e623594f.2c1a08","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.gm1913_czy_sie_laduje","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":760,"y":1970,"wires":[["e1cedfa.587432"],[]]},{"id":"72657d67.8dbff4","type":"delay","z":"b1f8b0b1.8198b","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"hour","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"outputs":1,"x":410,"y":1970,"wires":[["bddb9dd2.25504"]]},{"id":"73ad79b5ce4235e2","type":"api-current-state","z":"b1f8b0b1.8198b","name":"W domu?","server":"e623594f.2c1a08","version":3,"outputs":2,"halt_if":"home","halt_if_type":"str","halt_if_compare":"is","entity_id":"person.andrzej","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"dom","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":240,"y":1970,"wires":[["72657d67.8dbff4"],[]]},{"id":"e623594f.2c1a08","type":"server","name":"HA","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":30}]

Kologo wyślij mi flow przeanalizuje robię pod siebie :slight_smile:

“undefined” pojawia ci się na wejściu tej funkcji jako msg.wiadomosc z wcześniejszych nodów do której doklejasz "Andrzej masz "…
Prześledź wcześniejsze wejścia i wyjścia poszczególnych nodów za pomocą noda debug aby zobaczyć jaką wartość i co dostajesz jako msg.wiadomosc

Flow masz w poście skopiuj i zaimportuj u siebie

no właśnie ale przed nodem funkcji jest tylko switch i currwnt state


To na czerwono w tym momencie jeszcze nie istnieje - dopiero to tworzysz.
Wywal to albo ustaw na pusty w msg, przed wejściem do funkcji.

1 polubienie

Właśnie tak wcześniej robiłem że usuwałem ten wpis msg.wiadomosc i to nie działało i teraz już wiem dlaczego. Przez nie uwagę usunąłem ten wpis razem ze znakiem równa się i dla tego mi to nie chciało pójść. Wielkie dzięki za pomoc pozdrawiam :slight_smile: