I did the same and I created a flow, only with default Node-RED nodes, which is attached below.
Thanks for the flow, it's a great way to learn about Node-Red. I changed it a bit to prevent the Poll to be executed when it's turned off.
Node-RED developers advise to remove the "debug" or at least to disable them, as soon your flow is running fine.
I suggest to connect the status information to that "Text" node.
I understand but the Poll doesn't give anything on the standard output, and for now it's a nice way to see what's happening. If everything is running fine I will disable the debug output.
This is the input flow
Code: Select all
[
{
"id": "ce4eda975b3ddb38",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "c96c382a258260dc",
"type": "mqtt in",
"z": "ce4eda975b3ddb38",
"name": "From Domoticz",
"topic": "domoticz/out",
"qos": "2",
"datatype": "auto-detect",
"broker": "86f0c28c.790f4",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 200,
"y": 260,
"wires": [
[
"3bf37797e167b703"
]
]
},
{
"id": "3bf37797e167b703",
"type": "switch",
"z": "ce4eda975b3ddb38",
"name": "Split IDX",
"property": "payload.idx",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "307",
"vt": "num"
},
{
"t": "eq",
"v": "308",
"vt": "num"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 380,
"y": 260,
"wires": [
[
"e9fc7cf3fbb69a0c"
],
[
"1b3d8309d457b381"
]
]
},
{
"id": "21453f97270108fa",
"type": "change",
"z": "ce4eda975b3ddb38",
"name": "Set Poll",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": " { \"action\": \"poll\" }",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 780,
"y": 240,
"wires": [
[]
]
},
{
"id": "1b3d8309d457b381",
"type": "switch",
"z": "ce4eda975b3ddb38",
"name": "Split On/Off",
"property": "payload.nvalue",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "num"
},
{
"t": "eq",
"v": "1",
"vt": "num"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 570,
"y": 300,
"wires": [
[
"9407d73946af319b"
],
[
"56fd9b28c1869043"
]
]
},
{
"id": "9407d73946af319b",
"type": "change",
"z": "ce4eda975b3ddb38",
"name": "Set Stop",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": " { \"action\": \"stop\" }",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 780,
"y": 280,
"wires": [
[]
]
},
{
"id": "56fd9b28c1869043",
"type": "change",
"z": "ce4eda975b3ddb38",
"name": "Set Start",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": " { \"action\": \"start\" }",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 780,
"y": 320,
"wires": [
[]
]
},
{
"id": "2b6b6ab4e7178487",
"type": "inject",
"z": "ce4eda975b3ddb38",
"name": "Setup",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{ \"action\": \"setup\" }",
"payloadType": "json",
"x": 790,
"y": 360,
"wires": [
[]
]
},
{
"id": "e9fc7cf3fbb69a0c",
"type": "switch",
"z": "ce4eda975b3ddb38",
"name": "Split On/Off",
"property": "payload.nvalue",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "1",
"vt": "num"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 570,
"y": 240,
"wires": [
[
"21453f97270108fa"
]
]
},
{
"id": "86f0c28c.790f4",
"type": "mqtt-broker",
"name": "Domoticz",
"broker": "localhost",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "15",
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]
And the output
Code: Select all
[
{
"id": "16e2583208241e69",
"type": "tab",
"label": "Flow 3",
"disabled": false,
"info": "",
"env": []
},
{
"id": "1ad4e12651b84e4e",
"type": "mqtt out",
"z": "16e2583208241e69",
"name": "To Domoticz",
"topic": "domoticz/in",
"qos": "2",
"retain": "false",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "86f0c28c.790f4",
"x": 650,
"y": 380,
"wires": []
},
{
"id": "0ffc55e25886addc",
"type": "switch",
"z": "16e2583208241e69",
"name": "Split Laden",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 250,
"y": 360,
"wires": [
[
"e44416ef7e979380"
],
[
"7a9ef1d5d9dbc742"
]
]
},
{
"id": "e44416ef7e979380",
"type": "change",
"z": "16e2583208241e69",
"name": "Set Laden aan",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"idx\":308,\"nvalue\": 1}",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 440,
"y": 340,
"wires": [
[
"1ad4e12651b84e4e"
]
]
},
{
"id": "7a9ef1d5d9dbc742",
"type": "change",
"z": "16e2583208241e69",
"name": "Set Laden uit",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"idx\":308,\"nvalue\": 0}",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 430,
"y": 380,
"wires": [
[
"1ad4e12651b84e4e"
]
]
},
{
"id": "8edc862f95ab7351",
"type": "change",
"z": "16e2583208241e69",
"name": "Set Status",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"idx\":309,\"svalue\":payload}",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 430,
"y": 420,
"wires": [
[
"1ad4e12651b84e4e"
]
]
},
{
"id": "86f0c28c.790f4",
"type": "mqtt-broker",
"name": "Domoticz",
"broker": "localhost",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "15",
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]
And the DzVents script
Code: Select all
return {
active = true,
logging = {
-- level = domoticz.LOG_DEBUG, -- uncomment for development, else comment and use generic domoticz settings
marker = 'Laden'
},
on = {
timer = { 'at *:01' }
},
execute = function(dz, item)
local laden = dz.devices('Laden')
local poll = dz.devices('Poll')
local price = dz.devices('Actual Electricity Price')
local MaxElPrice = dz.variables('MaxElPrice').value
dz.notify ('Max electricity price: ' .. MaxElPrice)
local CurElPrice = price.sensorValue
dz.notify ('Current dynamic price: ' .. CurElPrice)
-- poll.switchOn()
if (item.isTimer) then
if (CurElPrice < MaxElPrice) then
laden.switchOn().checkFirst()
else
laden.switchOff().checkFirst()
end
end
end
}
I noticed that the Poll only gave the charger status (Occupied, Available, Charging), and not if the car is connected.