Call service node Data inject msg.payload

Since there is a thread for this I will piggy back.

I’m trying to send a payload (string) from my function node to call service node (telegram) but I’m getting this error:

“Call-service API error. Error Message: required key not provided @ data[‘message’]”

Here is my code from the function node which gets formatted for Pushbullet output (which works it but I’m trying to migrate to Telegram):

// format message for Pushbullet
duration           = 'Total washing time: '+wash_time;
energy_use         = 'Energy Use: '+energy_kwh+' kWh';
total_cost         = 'Total cost: £'+cost+'.';

var new_msg        = duration+'\n'+energy_use+'\n'+total_cost;
msg.payload        = new_msg;

return msg;

JSON format for Call service node:

{"message":"{{payload}}"}

I have another function node with test string and that one works fine, so I’m not sure why I am getting the error:

msg.payload   = "This is a test!";
return msg;

Sorry if this similar to what was above but I’m still fairly new to this and trying to learn.

Hi

I would try in your function block to clear up the msg, like doing return new_msg;

This will make sure nothing of the old msg falls through, it has made some of my blocks fail in the past.

If this dosn’t help, please post an export of your blocks.

Hi,

I tried creating newMsg but I’m still getting the same result. I am able to pass the string (message) to Pushbullet but not to Telegram. Here is my flow, maybe I’m doing something wrong:

[{"id":"863c428c.eece28","type":"tab","label":"Washing Machine","disabled":false,"info":""},{"id":"eccd4cba.dfe6d8","type":"function","z":"863c428c.eece28","name":"Calculate power","func":"var power = msg.data.state;\nvar timer = 5;\n\nvar total = flow.get(\"Total\");\n\nflow.set(\"current_output\", power);\nflow.set(\"timeout\", timer);\n\n//sprawdz czy istnieje zbior mocy\nif(!total || !total.length || total === undefined){\n    total = [];\n}\n\n//dodaj moc do poczatku zbioru\ntotal.unshift(power);\n//remove X elementh\nif(total[timer] === undefined) {\n    \n    flow.set(\"Total\", total);\n}\nelse {\n    total.splice(timer, 1);\n    flow.set(\"Total\", total);\n}\n\n//calculate average\nvar sum = total;\nfunction add(accumulator, a) {\n    return accumulator + a;\n}\nvar average = sum.reduce(add);\n\n//debug\nmsg.powerPerMinute = total;\nmsg.average = average / timer;\nmsg.payload = power;\n\nreturn msg;","outputs":1,"noerr":0,"x":118,"y":589,"wires":[["c3be8535.af26a","71953a3.2a8a444","4032f627.b07b7"]]},{"id":"c83d313f.e627b8","type":"json","z":"863c428c.eece28","name":"JSON","property":"payload","action":"","pretty":false,"x":88,"y":627,"wires":[["eccd4cba.dfe6d8"]]},{"id":"3f35df07.55de28","type":"poll-state","z":"863c428c.eece28","name":"Washing Machine","server":"d21bd910.f50568","version":1,"updateinterval":"60","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":true,"entity_id":"sensor.washing_machine_power_use","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":128,"y":665,"wires":[["c83d313f.e627b8"]]},{"id":"bad2d414.ee3fa8","type":"comment","z":"863c428c.eece28","name":"Washing Machine Notifications","info":"","x":168,"y":1121,"wires":[]},{"id":"39c72d9b.f63dfa","type":"function","z":"863c428c.eece28","name":"Random Naggings","func":"var nagging = [\n    \"Hurry up and get the laundry out of the washing machine\",\n    \"Stop being useless and get the laundry out\",\n    \"Get the laundry out, now!\",\n    \"How many times do I have to tell you to empty the washing machine\",\n    \"Washing machine is not going to empty itself - move your ass!\",\n    \"Remove your laundry or it will smell\",\n    \"Hey, did you hear me? - Get the laundry out! Now!\"\n\n    ];\n\n\nvar random = nagging[Math.floor(Math.random() * nagging.length)];\nmsg.payload = random;\nreturn msg;","outputs":1,"noerr":0,"x":413,"y":1197,"wires":[["1e8d326a.e2ab8e"]]},{"id":"d4ce2ee7.0ad03","type":"delay","z":"863c428c.eece28","name":"","pauseType":"delay","timeout":"60","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1029,"y":1197,"wires":[["8a93bfb6.9baab8"]]},{"id":"ebfd0ada.d780d8","type":"switch","z":"863c428c.eece28","name":"Nagging?","property":"nagging","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":155,"y":1197,"wires":[["39c72d9b.f63dfa"]]},{"id":"8a93bfb6.9baab8","type":"link out","z":"863c428c.eece28","name":"Delay","links":["cc5ee8.9f2a2118"],"x":1136,"y":1197,"wires":[]},{"id":"cc5ee8.9f2a2118","type":"link in","z":"863c428c.eece28","name":"Nagging","links":["8a93bfb6.9baab8"],"x":53,"y":1197,"wires":[["ebfd0ada.d780d8"]]},{"id":"b0f8a14a.d56488","type":"mqtt in","z":"863c428c.eece28","name":"Location","topic":"sensor/Lastmotion","qos":"2","datatype":"auto","broker":"f6099aae.0aa7f","x":763,"y":114,"wires":[["1d4afebe.810971"]]},{"id":"c3be8535.af26a","type":"debug","z":"863c428c.eece28","name":"Average Power","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"average","targetType":"msg","x":403,"y":665,"wires":[]},{"id":"b9d91572.f554f8","type":"state-machine","z":"863c428c.eece28","name":"Washing Machine","triggerProperty":"payload","triggerPropertyType":"msg","stateProperty":"payload","statePropertyType":"msg","outputStateChangeOnly":true,"throwException":false,"states":["off","ready","start","washing rinsing","washing heating","spinning","finishing","water in","heater on","heater off","water out","stopped"],"transitions":[{"name":"ready","from":"off","to":"ready"},{"name":"start","from":"off","to":"start"},{"name":"start","from":"ready","to":"start"},{"name":"rinse","from":"start","to":"water in"},{"name":"spin","from":"water in","to":"heater on"},{"name":"wash","from":"heater on","to":"washing heating"},{"name":"spin","from":"washing heating","to":"heater off"},{"name":"rinse","from":"heater off","to":"washing rinsing"},{"name":"spin","from":"washing rinsing","to":"spinning"},{"name":"rinse","from":"spinning","to":"washing rinsing"},{"name":"start","from":"spinning","to":"finishing"},{"name":"start","from":"washing rinsing","to":"finishing"},{"name":"ready","from":"finishing","to":"stopped"},{"name":"off","from":"stopped","to":"off"},{"name":"off","from":"*","to":"off"}],"x":831,"y":589,"wires":[["56e07247.f6039c","24e4c964.c47cbe"]]},{"id":"71953a3.2a8a444","type":"switch","z":"863c428c.eece28","name":"Switch","property":"average","propertyType":"msg","rules":[{"t":"lt","v":"0.15","vt":"num"},{"t":"btwn","v":"0.15","vt":"num","v2":"0.51","v2t":"num"},{"t":"btwn","v":"0.52","vt":"num","v2":"4","v2t":"num"},{"t":"btwn","v":"4","vt":"num","v2":"200","v2t":"num"},{"t":"btwn","v":"200","vt":"num","v2":"700","v2t":"num"},{"t":"gt","v":"700","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":383,"y":589,"wires":[["50d30f5f.e3c728"],["442d1843.07f4e"],["5f887fd8.06cca8"],["586c62fd.d49b4c"],["e503d51b.3bb3f"],["92f3cfb1.f589a"]]},{"id":"442d1843.07f4e","type":"change","z":"863c428c.eece28","name":"ready","rules":[{"t":"set","p":"payload","pt":"msg","to":"ready","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":532,"wires":[["b9d91572.f554f8","add62e99.80666"]]},{"id":"50d30f5f.e3c728","type":"change","z":"863c428c.eece28","name":"off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":494,"wires":[["b9d91572.f554f8","add62e99.80666"]]},{"id":"92f3cfb1.f589a","type":"change","z":"863c428c.eece28","name":"wash","rules":[{"t":"set","p":"payload","pt":"msg","to":"wash","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":684,"wires":[["b9d91572.f554f8","add62e99.80666"]]},{"id":"e503d51b.3bb3f","type":"change","z":"863c428c.eece28","name":"spin","rules":[{"t":"set","p":"payload","pt":"msg","to":"spin","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":646,"wires":[["b9d91572.f554f8","add62e99.80666"]]},{"id":"586c62fd.d49b4c","type":"change","z":"863c428c.eece28","name":"rinse","rules":[{"t":"set","p":"payload","pt":"msg","to":"rinse","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":608,"wires":[["b9d91572.f554f8","add62e99.80666"]]},{"id":"5f887fd8.06cca8","type":"change","z":"863c428c.eece28","name":"start","rules":[{"t":"set","p":"payload","pt":"msg","to":"start","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":570,"wires":[["b9d91572.f554f8","add62e99.80666"]]},{"id":"f96ac16f.e64298","type":"mqtt in","z":"863c428c.eece28","name":"Washing Machine On-Line","topic":"shellies/shelly1pm-washingmachine/online","qos":"2","datatype":"auto","broker":"f6099aae.0aa7f","x":158,"y":114,"wires":[["17870be6.9c845c"]]},{"id":"17870be6.9c845c","type":"debug","z":"863c428c.eece28","name":"Washing Machine On-Line","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":538,"y":114,"wires":[]},{"id":"d5b27269.578dd8","type":"mqtt in","z":"863c428c.eece28","name":"Washing Machine Relay Status","topic":"shellies/shelly1pm-BA53C4/relay/0","qos":"2","datatype":"auto","broker":"f6099aae.0aa7f","x":168,"y":171,"wires":[["b88ace8b.f964"]]},{"id":"b88ace8b.f964","type":"debug","z":"863c428c.eece28","name":"Washing Machine Status","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":528,"y":171,"wires":[]},{"id":"177dbaa0.270d85","type":"mqtt in","z":"863c428c.eece28","name":"Washing Machine Power","topic":"shellies/shelly1pm-BA53C4/relay/0/power","qos":"2","datatype":"auto","broker":"f6099aae.0aa7f","x":148,"y":228,"wires":[["bd354028.e1f478"]]},{"id":"279cd051.5f6a1","type":"mqtt in","z":"863c428c.eece28","name":"Washing Machine Energy","topic":"shellies/shelly1pm-BA53C4/relay/0/energy","qos":"2","datatype":"json","broker":"f6099aae.0aa7f","x":148,"y":285,"wires":[["f01b2ccc.6794d"]]},{"id":"bd354028.e1f478","type":"debug","z":"863c428c.eece28","name":"Wasching Machine Power","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":538,"y":228,"wires":[]},{"id":"f01b2ccc.6794d","type":"debug","z":"863c428c.eece28","name":"Washing Machine Energy","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":538,"y":285,"wires":[]},{"id":"1b8ccaa3.c7d835","type":"mqtt in","z":"863c428c.eece28","name":"Washing Machine Shelly Internal Temp","topic":"shellies/shelly1pm-BA53C4/temperature","qos":"2","datatype":"auto","broker":"f6099aae.0aa7f","x":198,"y":342,"wires":[["9429b726.34c1a8"]]},{"id":"9429b726.34c1a8","type":"debug","z":"863c428c.eece28","name":"Shelly WM Internal Temp","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":528,"y":342,"wires":[]},{"id":"480a4821.f0d76","type":"comment","z":"863c428c.eece28","name":"Washing Machine Shelly 1PM","info":"","x":170,"y":40,"wires":[]},{"id":"485d5d3a.2e6b14","type":"debug","z":"863c428c.eece28","name":"Test","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1053,"y":114,"wires":[]},{"id":"a83e3a2c.dce048","type":"debug","z":"863c428c.eece28","name":"Switch Test","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1030,"y":680,"wires":[]},{"id":"add62e99.80666","type":"rbe","z":"863c428c.eece28","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":790,"y":680,"wires":[["a83e3a2c.dce048"]]},{"id":"14ceedb6.5c9eba","type":"api-call-service","z":"863c428c.eece28","name":"Washing ON!","server":"d21bd910.f50568","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.washing_machine_running","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":118,"y":855,"wires":[["962b24d8.6ce518"]]},{"id":"cfd43d76.7f5dd","type":"function","z":"863c428c.eece28","name":"Controller","func":"// Define\nvar machine_status = msg.payload;\nvar washing_status = flow.get(\"washing_status\");\nvar power          = flow.get(\"current_output\");\n\n// Starting?\nif (machine_status === \"start\"){\n    flow.set(\"washing_status\", \"started\");\n    return[msg, null, null];\n} else if (machine_status === \"finishing\"){\n    flow.set(\"washing_status\", \"finishing\");\n    return[null, null, null];\n} else if ((machine_status === \"stopped\") && (washing_status === \"finishing\")){\n    flow.set(\"washing_status\", \"finished\");\n    flow.set(\"nagging\", true);\n    return[null, msg, null];\n} if ((power === 0) && (washing_status === \"finished\")){\n    flow.set(\"washing_status\", \"off\");\n    flow.set(\"nagging\", false);\n    return [null, null, msg];\n}","outputs":3,"noerr":0,"x":155,"y":931,"wires":[["14ceedb6.5c9eba"],["51d779ee.ff3c4"],["a458fa9c.ac5148"]],"outputLabels":["washing started","washing finished","washing machine off"]},{"id":"f9b2ce04.af0aa8","type":"link in","z":"863c428c.eece28","name":"Washing Controller","links":["24e4c964.c47cbe"],"x":53,"y":931,"wires":[["cfd43d76.7f5dd"]]},{"id":"4032f627.b07b7","type":"debug","z":"863c428c.eece28","name":"Power Debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":403,"y":513,"wires":[]},{"id":"a458fa9c.ac5148","type":"api-call-service","z":"863c428c.eece28","name":"Washing OFF!","server":"d21bd910.f50568","version":"1","service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.washing_machine_running","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":118,"y":1007,"wires":[[]]},{"id":"93ef487d.2a6cb","type":"debug","z":"863c428c.eece28","name":"Washing OFF","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":878,"y":855,"wires":[]},{"id":"962b24d8.6ce518","type":"api-current-state","z":"863c428c.eece28","name":"Washing Energy Use","server":"d21bd910.f50568","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.washing_machine_energy_use","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":423,"y":855,"wires":[["eb0e948e.f1889"]]},{"id":"eb0e948e.f1889","type":"function","z":"863c428c.eece28","name":"Set Start Energy","func":"//get starting energy value\nvar energy              = msg.payload\n//energy_kwh            = Math.round(((energy /1000) /60) * 100) / 100\n\n//store energy in variable\nflow.set(\"start_energy\", energy);\n\n//get starting time\nvar now                 = new Date();\nvar time                = now.getTime();\n\n//store time in variable\nflow.set(\"start_time\", time);\n\n//debug\nmsg.start_energy        = flow.get(\"start_energy\");\nmsg.start_time          = flow.get(\"start_time\");\nmsg.washing_status      = flow.get(\"washing_status\");\nreturn msg;","outputs":1,"noerr":0,"x":660,"y":855,"wires":[[]]},{"id":"51272802.3811c8","type":"function","z":"863c428c.eece28","name":"Total Wash Time","func":"// energy calculation\nvar stop_energy    = msg.payload;\nvar start_energy   = flow.get(\"start_energy\");\nvar energy         = (stop_energy - start_energy);\nvar energy_kwh     = Math.round(((energy /1000) /60) * 100) / 100;\n\n// cost per unit of energy\nvar unit_cost      = 0.1874;\nvar cost           = Math.round((energy_kwh * unit_cost) * 100) / 100;\n\n//check time\nvar now     = new Date();\nvar time    = now.getTime();\nvar year    = now.getFullYear();\nvar month   = now.getMonth()+1; \nvar day     = now.getDate();\nvar hour    = now.getHours();\nvar minute  = now.getMinutes();\nvar second  = now.getSeconds();\n\nif(month.toString().length == 1){\n    month = '0'+month;\n}\nif(day.toString().length == 1){\n    day = '0'+day;\n}   \nif(hour.toString().length == 1){\n    hour = '0'+hour;\n}\nif(minute.toString().length == 1){\n    minute = '0'+minute;\n}\nif(second.toString().length == 1){\n    second = '0'+second;\n}\n\n//store time in variable\nvar start_time = flow.get(\"start_time\");\nvar wash_ms = (time - start_time);\n\nvar miliseconds   = (wash_ms % 1000);\nvar seconds       = Math.floor((wash_ms / 1000) % 60);\nvar minutes       = Math.floor((wash_ms / (60 * 1000)) % 60);\nvar hours         = Math.floor((wash_ms / (3600 * 1000)) % 60);\n\n// set timeformat\nif (hours !== 0){\n    hours = hours.toString();\n    if (minutes.toString().length == 1){\n        minutes   = '0'+minutes;\n    }\n    if (seconds.toString().length == 1){\n        seconds = '0'+seconds;\n    }\n    wash_time = hours+'h '+minutes+'m '+seconds+'s.';\n} else if (minutes !== 0){\n    minutes = minutes.toString();\n    if (seconds.toString().length ==1){\n        seconds = '0'+seconds;\n    }\n    wash_time = minutes+'m '+seconds+'s.';\n} else {\n    seconds   = seconds.toString()\n    wash_time = seconds+'s.';\n}\n\n// change to string\nenergy_kwh       = energy_kwh.toString();\ncost             = cost.toString();\n\n// topic generation for Pushbullet\nvar topic        = year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second+' Washing has finished!';\n\n// format message for Pushbullet\nduration         = 'Total washing time: '+wash_time;\nenergy_use       = 'Energy Use: '+energy_kwh+' kWh';\ntotal_cost       = 'Total cost: £'+cost+'.';\n\nmsg.topic        = topic;\ntime             = duration+'\\n'+energy_use+'\\n'+total_cost;\n\nvar newMsg = { payload: time };\n\nreturn newMsg;\n\n","outputs":1,"noerr":0,"x":660,"y":931,"wires":[["93ef487d.2a6cb","c8843270.1d88c8","75be320f.6e4724","96903c7b.f595f8"]]},{"id":"51d779ee.ff3c4","type":"api-current-state","z":"863c428c.eece28","name":"Washing Energy Use","server":"d21bd910.f50568","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.washing_machine_energy_use","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":423,"y":931,"wires":[["51272802.3811c8"]]},{"id":"96903c7b.f595f8","type":"pushbullet","z":"863c428c.eece28","config":"825dadf.af6ca5","pushtype":"note","title":"","chan":"","name":"Washing ready!","x":1080,"y":940,"wires":[]},{"id":"c8843270.1d88c8","type":"change","z":"863c428c.eece28","name":"Finished","rules":[{"t":"set","p":"payload","pt":"msg","to":"Your washing is ready!","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":858,"y":1007,"wires":[["1e8d326a.e2ab8e"]]},{"id":"64bf3a7f.6878c4","type":"cast-to-client","z":"863c428c.eece28","name":"Bedroom","url":"","contentType":"","message":"","language":"en","ip":"192.168.1.26","port":"8009","volume":"40","x":839,"y":1159,"wires":[["d4ce2ee7.0ad03"]]},{"id":"b8884e71.a6a318","type":"cast-to-client","z":"863c428c.eece28","name":"Living Room","url":"","contentType":"","message":"","language":"en","ip":"192.168.1.26","port":"8009","volume":"50","x":849,"y":1235,"wires":[["d4ce2ee7.0ad03"]]},{"id":"1e8d326a.e2ab8e","type":"function","z":"863c428c.eece28","name":"Redirect","func":"var location = flow.get(\"last_motion\");\n\nif((location === \"Hall Upstairs\") || (location === \"Bathroom\")){\n    return [msg, null];\n} if((location === \"Kitchen\") || (location === \"Living Room\")){\n    return [null, msg];\n}\n","outputs":2,"noerr":0,"x":630,"y":1197,"wires":[["64bf3a7f.6878c4"],["b8884e71.a6a318"]]},{"id":"1d4afebe.810971","type":"function","z":"863c428c.eece28","name":"Save","func":"var location = msg.payload;\nflow.set(\"last_motion\", location);\n\nreturn msg;","outputs":1,"noerr":0,"x":913,"y":114,"wires":[["485d5d3a.2e6b14"]]},{"id":"3df959d1.587c56","type":"mqtt out","z":"863c428c.eece28","name":"Washing Status","topic":"sensor/washing_status","qos":"2","retain":"true","broker":"f6099aae.0aa7f","x":413,"y":1273,"wires":[]},{"id":"922b4cc0.b4ccf8","type":"function","z":"863c428c.eece28","name":"Status","func":"var status = msg.payload;\n\nif (status === \"off\"){\n    msg.payload = \"OFF\";\n} if (status === \"ready\"){\n    msg.payload = \"READY\";\n} if(status === \"start\"){\n    msg.payload = \"STARTING\";\n} if(status === \"water in\"){\n    msg.payload = \"WATER IN\";\n} if(status === \"heater on\"){\n    msg.payload = \"HEATING WATER\";\n} if(status === \"washing heating\"){\n    msg.payload = \"WASHING / HEATING\";\n} if(status === \"heater off\"){\n    msg.payload = \"HEATER OFF\";\n} if(status === \"washing rinsing\"){\n    msg.payload = \"WASHING / RINSING\";\n} if(status === \"spinning\"){\n    msg.payload = \"SPINNING\";\n} if(status === \"finishing\"){\n    msg.payload = \"FINISHING\";\n} if(status === \"stopped\"){\n    msg.payload = \"STOPPED\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":145,"y":1273,"wires":[["3df959d1.587c56"]]},{"id":"56e07247.f6039c","type":"debug","z":"863c428c.eece28","name":"Washing State","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1040,"y":540,"wires":[]},{"id":"dc164db5.cf953","type":"inject","z":"863c428c.eece28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":782,"y":247,"wires":[["5f887fd8.06cca8"]]},{"id":"78c5d7b4.be0d68","type":"inject","z":"863c428c.eece28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":782,"y":287,"wires":[["586c62fd.d49b4c"]]},{"id":"70d2e3be.926bc4","type":"inject","z":"863c428c.eece28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":782,"y":327,"wires":[["e503d51b.3bb3f"]]},{"id":"daf5112f.1d2e8","type":"inject","z":"863c428c.eece28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":782,"y":367,"wires":[["92f3cfb1.f589a"]]},{"id":"4c318a9c.b0ee64","type":"inject","z":"863c428c.eece28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":782,"y":207,"wires":[["442d1843.07f4e"]]},{"id":"f8dbe41a.4246a","type":"inject","z":"863c428c.eece28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":782,"y":167,"wires":[["50d30f5f.e3c728"]]},{"id":"1fcf2221.d5119e","type":"link in","z":"863c428c.eece28","name":"Status Sensor","links":["24e4c964.c47cbe"],"x":53,"y":1273,"wires":[["922b4cc0.b4ccf8"]]},{"id":"980cb55b.cc3838","type":"comment","z":"863c428c.eece28","name":"Washing Calculations","info":"","x":138,"y":779,"wires":[]},{"id":"db758218.f59c08","type":"comment","z":"863c428c.eece28","name":"Washing Machine Notifications","info":"","x":168,"y":437,"wires":[]},{"id":"ab61dc2d.8d08","type":"inject","z":"863c428c.eece28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":136,"y":1425,"wires":[["1efbe9e7.93e06e","23b4828d.b6f45e"]]},{"id":"6962732f.3b457c","type":"debug","z":"863c428c.eece28","name":"Telegram","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":630,"y":1425,"wires":[]},{"id":"1efbe9e7.93e06e","type":"function","z":"863c428c.eece28","name":"Test","func":"msg.payload   = \"This is a test!\";\nreturn msg;","outputs":1,"noerr":0,"x":285,"y":1425,"wires":[["32b49290.21700e","611b29ce.a60bc8"]]},{"id":"32b49290.21700e","type":"api-call-service","z":"863c428c.eece28","name":"Telegram Test","server":"d21bd910.f50568","version":1,"debugenabled":false,"service_domain":"telegram_bot","service":"send_message","entityId":"","data":"{\"message\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":460,"y":1425,"wires":[["6962732f.3b457c"]]},{"id":"9d55a832.59d3f8","type":"inject","z":"863c428c.eece28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":383,"y":1007,"wires":[["51272802.3811c8"]]},{"id":"24e4c964.c47cbe","type":"link out","z":"863c428c.eece28","name":"Washing Machine State","links":["1fcf2221.d5119e","f9b2ce04.af0aa8","5a608ae9.cb0b6c","d52b594b.5fb358"],"x":975,"y":620,"wires":[]},{"id":"611b29ce.a60bc8","type":"debug","z":"863c428c.eece28","name":"Test","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":430,"y":1501,"wires":[]},{"id":"23b4828d.b6f45e","type":"debug","z":"863c428c.eece28","name":"Timestamp","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":450,"y":1558,"wires":[]},{"id":"75be320f.6e4724","type":"api-call-service","z":"863c428c.eece28","name":"Telegram Test","server":"d21bd910.f50568","version":1,"debugenabled":false,"service_domain":"telegram_bot","service":"send_message","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1080,"y":980,"wires":[[]]},{"id":"d21bd910.f50568","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true},{"id":"f6099aae.0aa7f","type":"mqtt-broker","z":"","name":"MQTT","broker":"192.168.1.7","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"825dadf.af6ca5","type":"pushbullet-config","z":"","name":"Sloma"}]

Thanks.

OK, I have found the cause of why my messages are not being sent to telegram. It was this line:

time             = duration+'\n'+energy_use+'\n'+total_cost;

If I remove line dividers (\n) it works fine but it sends whole message as one long line. So, it kind of works but now I wonder if I can separate the lines somehow for Telegram or is it only that only liners are allowed through service call.

Any advice here?

From https://stackoverflow.com/questions/50018785/telegram-rest-api-send-newline-in-message-text it should be %0A
Have you tried that?
GV

Thx, I tried this:

time             = duration+'%0A'+energy_use+'%0A'+total_cost;

but it doesn’t seem to work, %0A is passed within the message as string instead of breaking the line.

I am using node-red-contrib-chatbot with telegram and \n works as expected…
GV

I tried using node-red-contrib-chatbot but it doesn’t work on my setup. I am forced to use service call in node red and with this setup \n is causing the problem mentioned earlier.

Signed up specifically to say thank you for that @Kermit, i’ve been trying to figure out how to get the payload data in to something else and this helped so much!! Thank you.

Hello everyone, tried to find the solution here but still struggling.

My case : I have 16 switches that I want to limit the time they stay on. I am hoping to use a template instead of 16 times the same flow.

The flow is simple :

Having trouble with the syntax of the service. It should pick up which zone is on and turn it off.

Can anyone guide me with the right syntax ? Thanks !!

For anyone wondering how to solve what @mviamin asked:

Put the data for the service call in a data object inside the payload object. So the resulting structure starting from the message itself should be like this:

{
   "msg":{
      "payload":{
         "data":{
            "brightness":"150",
            "rgb_color":[
               255,
               0,
               0
            ],
            "transition":3
         }
      }
   }
}

If you have formatted your data like this you can leave the “data” field in the “call service” node empty, node-red will put the data object in the right place.

I have used this myself to control some lights as you might’ve guessed.

1 Like

Hi @bollepapzak,
Can you please share a node red example how you did it?

Sorry but I’m not understanding your solution and would also like to solve this problem.

Thanks.

Found a solution :slight_smile:

[{"id":"88e8d5d3c777921f","type":"ha-get-entities","z":"a836e4ac72800a2c","name":"","server":"f56de91.b429118","version":0,"rules":[{"property":"entity_id","logic":"starts_with","value":"light.stufe_","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":290,"y":1020,"wires":[["e9600975185c4f97"]]},{"id":"807584f99a5e5dde","type":"inject","z":"a836e4ac72800a2c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":1020,"wires":[["88e8d5d3c777921f"]]},{"id":"d26ffd31c9f041c2","type":"split","z":"a836e4ac72800a2c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":130,"y":1100,"wires":[["9061c7576153e7ef"]]},{"id":"9061c7576153e7ef","type":"delay","z":"a836e4ac72800a2c","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":310,"y":1100,"wires":[["d9ff539fa09ff079"]]},{"id":"b9e4e26a11e79c29","type":"api-call-service","z":"a836e4ac72800a2c","name":"","server":"f56de91.b429118","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"{}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":470,"y":1180,"wires":[[]]},{"id":"e9600975185c4f97","type":"sort","z":"a836e4ac72800a2c","name":"","order":"ascending","as_num":false,"target":"payload","targetType":"msg","msgKey":"","msgKeyType":"elem","seqKey":"payload","seqKeyType":"msg","x":450,"y":1020,"wires":[["d26ffd31c9f041c2"]]},{"id":"0f42efea9f80e697","type":"debug","z":"a836e4ac72800a2c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":430,"y":1240,"wires":[]},{"id":"d9ff539fa09ff079","type":"change","z":"a836e4ac72800a2c","name":"","rules":[{"t":"set","p":"payload.data.entity_id","pt":"msg","to":"payload.entity_id","tot":"msg"},{"t":"set","p":"payload.data.brightness_pct","pt":"msg","to":"50","tot":"num"},{"t":"set","p":"payload.data.rgb_color","pt":"msg","to":"[255,10,10]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":1180,"wires":[["b9e4e26a11e79c29","0f42efea9f80e697"]]},{"id":"f56de91.b429118","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

For me it only worked if I add the entity_id inside msg.payload.data.

This strangely works, at least for latest version of NR, even though it’s highlighting it in red. Took me so long to figure it out. Prior to that I had it working through a script node which was altering data, but it stopped working after latest update for some reason.

Turns out the whole time I could’ve just done this… Duh.

This is for Aqara Magic Cube. Here’s my data in the end:

{"brightness_step_pct": {{payload.event.args.relative_degrees}}}

Did you end up getting this working? you can have multiple payloads if they have different names.

in the get entities node you can change the output to something like payloadentites and then in the call service node under entity instead of {{payload}} have {{payloadentites}}.

Hello together,

I hope somebody can help me… I would like to inject somehow a “service” but I’m unable till now. Maybe some of you could help me?

My full code…

[{"id":"fe212185f847cbcc","type":"api-call-service","z":"96dd39fdae667f20","name":"Benachrichtige Markus Handy","server":"402eece2cebcf46c","version":5,"debugenabled":false,"domain":"notify","service":"{{Nachricht_Empfaenger}}","areaId":[],"deviceId":[],"entityId":[],"data":"{\"title\":\"{{{Nachricht_Titel}}}\",\"message\":\"{{{Nachricht_Text}}}\",\"data\":{\"clickAction\":\"{{{Nachricht_KlickAktion}}}\"}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1730,"y":120,"wires":[[]]},{"id":"402eece2cebcf46c","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":": ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"default","statusTimeFormat":"h:m","enableGlobalContextStore":false}]

Idea… I set the receiver of a message…

…and use it in the call_service node…

…but it leads to…

HomeAssistantError: Service notify.mobile_app_sm_s908b not found.

SOLVED > The service was renamed and my HA restarted. It is working as expected now