Hey!
Off course I can share the code.
Quick and dirty
Hope it helps! If not raise your hands!
- Copy/Past the JSON into node red:
- burger symbol in Node-Red (upper right corner)
- import: past the copied JSON below
- place the nodes in a new flow window
[{"id":"94936bfddddb4650","type":"http request","z":"c7120bbd05d84382","name":"http request GET","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://192.168.178.161/api/e-mobility/config/chargemode","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Authorization","valueType":"msg","valueValue":"bearer"}],"x":970,"y":260,"wires":[["20bbc142a981ef08"]]},{"id":"20bbc142a981ef08","type":"debug","z":"c7120bbd05d84382","name":"state reached","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1180,"y":260,"wires":[]},{"id":"99844a53c8d56d88","type":"http request","z":"c7120bbd05d84382","name":"http request PUT","method":"PUT","ret":"obj","paytoqs":"ignore","url":"http://192.168.178.161/api/e-mobility/config/chargemode","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Authorization","valueType":"msg","valueValue":"bearer"}],"x":710,"y":260,"wires":[["94936bfddddb4650","49969fe6a9c3805c"]]},{"id":"735ba62bbdcdb6eb","type":"inject","z":"c7120bbd05d84382","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"00 12 * * *","once":true,"onceDelay":0.1,"topic":"","payload":"{\"grant_type\":\"password\",\"client_id\":\"emos\",\"client_secret\":56951025,\"username\":\"admin\",\"password\":\"PASSWORD\"}","payloadType":"json","x":190,"y":440,"wires":[["846f1f51841513bb"]]},{"id":"af10bfd8baaabfa5","type":"function","z":"c7120bbd05d84382","name":"global bearer String","func":"var msg1 = { bearer:\"\"}\nvar auth = \"Bearer\"\nvar bearer_kostal = msg.payload.access_token\n\n\nmsg1.bearer = auth.concat(\" \", bearer_kostal);\nglobal.set(\"Kostal_bearer\", msg1.bearer);\nreturn msg1;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":440,"wires":[["64e91ffcb634fab7"]]},{"id":"e5cb3b11d88b2d8f","type":"function","z":"c7120bbd05d84382","name":"mode parser","func":"var msg1 = { payload: { \"mode\": 0, \"bearer\":0 } }\nvar SelectedMode = msg.payload\nvar mode\nif (SelectedMode === \"Lock Mode\") {\n mode = '{ \"mode\": \"lock\", \"mincharginpowerquota\": 0, \"minpvpowerquota\": 100 }';\n}\nelse if (SelectedMode === \"Power Mode\") {\n mode ='{ \"mode\": \"grid\", \"mincharginpowerquota\": 0, \"minpvpowerquota\": 100 }';\n}\nelse if (SelectedMode === \"Solar Pure Mode\") {\n mode = '{ \"mode\": \"pv\", \"mincharginpowerquota\": 0, \"minpvpowerquota\": 100 }';\n\n}\nelse if (SelectedMode === \"Solar Plus Mode\") {\n mode = '{ \"mode\": \"hybrid\", \"mincharginpowerquota\": 0, \"minpvpowerquota\": 100 }';\n\n}\n\nmsg1.payload = mode;\nmsg1.bearer = global.get(\"Kostal_bearer\") ;\nreturn msg1;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":260,"wires":[["99844a53c8d56d88"]]},{"id":"129b483a188d30d9","type":"trigger-state","z":"c7120bbd05d84382","name":"Wallbox PhaseUsage","server":"ba0f7c7d.deae9","version":4,"inputs":0,"outputs":3,"exposeAsEntityConfig":"","entityId":"input_select.wallbox_phaseusage","entityIdType":"exact","debugEnabled":false,"constraints":[],"customOutputs":[{"messageType":"default","messageValue":"","messageValueType":"json","comparatorPropertyType":"always","comparatorPropertyValue":"","comparatorType":"is","comparatorValue":"","comparatorValueDataType":"str"}],"outputInitially":false,"stateType":"str","enableInput":false,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":200,"y":360,"wires":[["07116615698274ec"],[],[]]},{"id":"07116615698274ec","type":"function","z":"c7120bbd05d84382","name":"mode parser","func":"var msg1 = { payload: { \"mode\": 0, \"bearer\":0 } }\nvar SelectedMode = msg.payload\nvar mode\nif (SelectedMode === \"3 phasig\") {\n mode = '{\"phase_usage\":0}';\n}\nelse if (SelectedMode === \"1 phasig\") {\n mode = '{\"phase_usage\":1}';\n}\n\nmsg1.payload = mode;\nmsg1.bearer = global.get(\"Kostal_bearer\") ;\nreturn msg1;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":360,"wires":[["552dd6fe4113b4eb"]]},{"id":"ced1ae3f51a47cfc","type":"debug","z":"c7120bbd05d84382","name":"state reached","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1180,"y":360,"wires":[]},{"id":"552dd6fe4113b4eb","type":"http request","z":"c7120bbd05d84382","name":"http request PUT","method":"PUT","ret":"obj","paytoqs":"ignore","url":"http://192.168.178.161/api/e-mobility/phaseusage","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Authorization","valueType":"msg","valueValue":"bearer"}],"x":710,"y":360,"wires":[["c13dd19967cd7b74"]]},{"id":"c13dd19967cd7b74","type":"http request","z":"c7120bbd05d84382","name":"http request GET","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://192.168.178.161/api/e-mobility/phaseusage","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[{"keyType":"other","keyValue":"Authorization","valueType":"msg","valueValue":"bearer"}],"x":970,"y":360,"wires":[["ced1ae3f51a47cfc"]]},{"id":"49969fe6a9c3805c","type":"debug","z":"c7120bbd05d84382","name":"state reached","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1096.7652587890625,"y":148.5565185546875,"wires":[]},{"id":"18eac1025038a0e4","type":"http request","z":"c7120bbd05d84382","name":"http request GET","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://192.168.178.161/api/kostal-energyflow/configuration/batteryusage","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Authorization","valueType":"msg","valueValue":"bearer"}],"x":970,"y":560,"wires":[["a495f79658f60b16"]]},{"id":"a495f79658f60b16","type":"debug","z":"c7120bbd05d84382","name":"state reached","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1180,"y":560,"wires":[]},{"id":"a4d6e0cae28be6cf","type":"http request","z":"c7120bbd05d84382","name":"http request PUT","method":"PUT","ret":"obj","paytoqs":"ignore","url":"http://192.168.178.161/api/kostal-energyflow/configuration/batteryusage","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Authorization","valueType":"msg","valueValue":"bearer"}],"x":710,"y":560,"wires":[["18eac1025038a0e4","93e605fef2ef9f16"]]},{"id":"9212201553e219f7","type":"trigger-state","z":"c7120bbd05d84382","name":"Wallbox BatteryChargeMode","server":"ba0f7c7d.deae9","version":4,"inputs":0,"outputs":3,"exposeAsEntityConfig":"","entityId":"input_select.wallbox_batterychargemode","entityIdType":"exact","debugEnabled":false,"constraints":[],"customOutputs":[{"messageType":"default","messageValue":"","messageValueType":"json","comparatorPropertyType":"always","comparatorPropertyValue":"","comparatorType":"is","comparatorValue":"","comparatorValueDataType":"str"}],"outputInitially":false,"stateType":"str","enableInput":false,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":220,"y":560,"wires":[["c85146218b4d714b"],[],[]]},{"id":"c85146218b4d714b","type":"function","z":"c7120bbd05d84382","name":"mode parser","func":"var msg1 = { payload: { \"mode\": 0, \"bearer\":0 } }\nvar SelectedMode = msg.payload\nvar mode\nif (SelectedMode === \"Hausbatterie nutzen\") {\n mode = \"true\";\n}\nelse if (SelectedMode === \"Hausbatterie nicht nutzen\") {\n mode = \"false\";\n}\n\n\nmsg1.payload = mode;\nmsg1.bearer = global.get(\"Kostal_bearer\") ;\nreturn msg1;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":560,"wires":[["a4d6e0cae28be6cf","9cfd60b22e4fa216"]]},{"id":"9cfd60b22e4fa216","type":"debug","z":"c7120bbd05d84382","name":"state reached","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":660,"y":660,"wires":[]},{"id":"93e605fef2ef9f16","type":"debug","z":"c7120bbd05d84382","name":"state reached","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1000,"y":640,"wires":[]},{"id":"64e91ffcb634fab7","type":"debug","z":"c7120bbd05d84382","name":"state reached","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":858.9674072265625,"y":438.016357421875,"wires":[]},{"id":"4c3b2a1059f43b65","type":"debug","z":"c7120bbd05d84382","name":"state reached","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":660,"y":500,"wires":[]},{"id":"846f1f51841513bb","type":"http request","z":"c7120bbd05d84382","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"http://192.168.178.161/api/web-login/token","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"content-type","valueType":"other","valueValue":"application/x-www-form-urlencoded"}],"x":450,"y":440,"wires":[["af10bfd8baaabfa5","4c3b2a1059f43b65"]]},{"id":"67bc08a33b571706","type":"trigger-state","z":"c7120bbd05d84382","name":"Wallbox ActiveChargeMode","server":"ba0f7c7d.deae9","version":4,"inputs":0,"outputs":3,"exposeAsEntityConfig":"","entityId":"input_select.wallbox_activechargemode","entityIdType":"exact","debugEnabled":false,"constraints":[],"customOutputs":[{"messageType":"default","messageValue":"","messageValueType":"json","comparatorPropertyType":"always","comparatorPropertyValue":"","comparatorType":"is","comparatorValue":"","comparatorValueDataType":"str"}],"outputInitially":false,"stateType":"str","enableInput":false,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":220,"y":260,"wires":[["e5cb3b11d88b2d8f"],[],[]]},{"id":"ba0f7c7d.deae9","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
- Implement the helpers within HomeAssistant:
- Settings/Helper → Create Helper → i
- name, configure the 3 helpers like shown in the pictures
- Input_select, type dropdown
- EXACTLY the same
![:wink: :wink:](https://community.home-assistant.io/images/emoji/twitter/wink.png?v=12)
- Configure Node-RED flow:
3.1 inject Node - Password to web app
- Open the inject Node and add your personal password in the payload. (Password of the (local) KSEM Websit)
{“grant_type”:“password”,“client_id”:“emos”,“client_secret”:56951025,“username”:“admin”,“password”:“PLACE YOUR PASSWORD HERE”}
3.2 Update IP adress to KMSE
- Update IP adresse of ALL yellow/ http request nodes
- Deploy and test