Hello all
I'm quit new to node red so I can use some help to learn and get my test setup working
The idea is to switch a shelly1 plus relay by mqtt in function of the state of charger of a battery.
I setup a mosquitto broker on my freenas system en works fine, I'm running node red on a cerbo gx device. I'm already able to controle the shelly relay manualy in node red by "inject" function. Now at this point I want to switch the relay automatic in funtion of the state of charge. The state of charge comes in as "msg.payload: number 99 (value from 0-99)" How can I use this value to switch on the relay above 95 and off below 94. I guess I need the "function" node, I tried already but with no succes.
[
{
"id": "a09ba820e62bca12",
"type": "tab",
"label": "Relay control by SOC",
"disabled": false,
"info": ""
},
{
"id": "84080a165d3ecc41",
"type": "mqtt in",
"z": "a09ba820e62bca12",
"name": "",
"topic": "#",
"qos": "2",
"datatype": "auto",
"broker": "69fe757f5b3e5904",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 610,
"y": 540,
"wires": [
[
"485ad33ac9dac72f"
]
]
},
{
"id": "485ad33ac9dac72f",
"type": "debug",
"z": "a09ba820e62bca12",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 890,
"y": 540,
"wires": []
},
{
"id": "470d5864d51bf32d",
"type": "inject",
"z": "a09ba820e62bca12",
"name": "on",
"props": [
{
"p": "topic",
"vt": "str"
},
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "shelly1-3c610572ccf0/rpc",
"payload": "{\"id\":123,\"src\":\"/shelly1-3c610572ccf0/rpc\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":true}}",
"payloadType": "json",
"x": 610,
"y": 360,
"wires": [
[
"c98088e16dea5d1f"
]
]
},
{
"id": "c98088e16dea5d1f",
"type": "mqtt out",
"z": "a09ba820e62bca12",
"name": "",
"topic": "",
"qos": "2",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "69fe757f5b3e5904",
"x": 870,
"y": 360,
"wires": []
},
{
"id": "a4520e71012ae481",
"type": "inject",
"z": "a09ba820e62bca12",
"name": "off",
"props": [
{
"p": "topic",
"vt": "str"
},
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "shelly1-3c610572ccf0/rpc",
"payload": "{\"id\":123,\"src\":\"/shelly1-3c610572ccf0/rpc\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":false}}",
"payloadType": "json",
"x": 610,
"y": 400,
"wires": [
[
"c98088e16dea5d1f"
]
]
},
{
"id": "693108d92e429651",
"type": "function",
"z": "a09ba820e62bca12",
"name": "start soc>95",
"func": "",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 590,
"y": 300,
"wires": [
[
"c98088e16dea5d1f"
]
]
},
{
"id": "3e868bb0b398c142",
"type": "inject",
"z": "a09ba820e62bca12",
"name": "Toggle",
"props": [
{
"p": "topic",
"vt": "str"
},
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "shelly1-3c610572ccf0/rpc",
"payload": "{\"id\":123,\"src\":\"/shelly1-3c610572ccf0/rpc\",\"method\":\"Switch.Toggle\",\"params\":{\"id\":0,\"on\":true}}",
"payloadType": "json",
"x": 610,
"y": 440,
"wires": [
[
"c98088e16dea5d1f"
]
]
},
{
"id": "e84afd6f351b0c23",
"type": "inject",
"z": "a09ba820e62bca12",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "95",
"payloadType": "num",
"x": 190,
"y": 300,
"wires": [
[
"693108d92e429651"
]
]
},
{
"id": "bd6fe2ac1bd15299",
"type": "inject",
"z": "a09ba820e62bca12",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "94",
"payloadType": "num",
"x": 190,
"y": 360,
"wires": [
[
"693108d92e429651"
]
]
},
{
"id": "69fe757f5b3e5904",
"type": "mqtt-broker",
"name": "",
"broker": "192.168.1.118",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"sessionExpiry": ""
}
]