[SOLVED] Node-Red And with raw

I’ll try the formatted version:

[
    {
        "id": "3beede20.2a5162",
        "type": "openhab2-in",
        "z": "7815450d.2de7ec",
        "name": "",
        "controller": "e6d015f.73ddee8",
        "itemname": "SwNoteRedTest",
        "x": 987,
        "y": 249,
        "wires": [
            [
                "d1f28535.7ccf88"
            ],
            []
        ]
    },
    {
        "id": "2da3c6c.f70303a",
        "type": "debug",
        "z": "7815450d.2de7ec",
        "name": "",
        "active": false,
        "console": "false",
        "complete": "payload",
        "x": 1383,
        "y": 252,
        "wires": []
    },
    {
        "id": "d1f28535.7ccf88",
        "type": "change",
        "z": "7815450d.2de7ec",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "item",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1017,
        "y": 113,
        "wires": [
            [
                "2da3c6c.f70303a",
                "d97f3399.c8b93"
            ]
        ]
    },
    {
        "id": "d97f3399.c8b93",
        "type": "and-gate",
        "z": "7815450d.2de7ec",
        "name": "",
        "rules": [
            {
                "t": "eq",
                "v": "ON",
                "vt": "str",
                "propertyType": "msg",
                "property": "payload",
                "topic": "SwNoteRedTest"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "str",
                "propertyType": "msg",
                "property": "payload",
                "topic": "Darkness"
            }
        ],
        "outputTopic": "",
        "gateType": "and",
        "emitOnlyIfTrue": false,
        "x": 1375,
        "y": 164,
        "wires": [
            []
        ]
    },
    {
        "id": "1b760db2.7d3002",
        "type": "bigtimer",
        "z": "7815450d.2de7ec",
        "outtopic": "Darkness",
        "outpayload1": "1",
        "outpayload2": "0",
        "name": "Darkness",
        "lat": "55.6759",
        "lon": "12.5655",
        "starttime": "5004",
        "endtime": "5003",
        "startoff": 0,
        "endoff": 0,
        "offs": 0,
        "outtext1": "",
        "outtext2": "",
        "timeout": 1440,
        "sun": true,
        "mon": true,
        "tue": true,
        "wed": true,
        "thu": true,
        "fri": true,
        "sat": true,
        "jan": true,
        "feb": true,
        "mar": true,
        "apr": true,
        "may": true,
        "jun": true,
        "jul": true,
        "aug": true,
        "sep": true,
        "oct": true,
        "nov": true,
        "dec": true,
        "day1": 0,
        "month1": 0,
        "day2": 0,
        "month2": 0,
        "day3": 0,
        "month3": 0,
        "day4": 0,
        "month4": 0,
        "day5": 0,
        "month5": 0,
        "d1": 0,
        "w1": 0,
        "d2": 0,
        "w2": 0,
        "d3": 0,
        "w3": 0,
        "d4": 0,
        "w4": 0,
        "d5": 0,
        "w5": 0,
        "suspend": false,
        "random": false,
        "repeat": true,
        "atstart": true,
        "odd": false,
        "even": false,
        "x": 1184,
        "y": 408,
        "wires": [
            [
                "d97f3399.c8b93"
            ],
            [],
            []
        ]
    },
    {
        "id": "e6d015f.73ddee8",
        "type": "openhab2-controller",
        "z": "",
        "name": "Openhab",
        "protocol": "http",
        "host": "192.168.1.109",
        "port": "8080",
        "path": "",
        "username": "",
        "password": ""
    }
]

Hi read the documentation for the: node-red-contrib-openhab2 (node) - Node-RED

  • openhab2-in

Listens to state changes of a selected openHAB Item.

Configuration:

Name : Optionally specify a name
Controller : Select the openHAB controller
Item : Select the Item to monitor
Messages injected in NodeRED flows (2 channels):

Channel 1:

msg.item : the item’s itemname (not label)
msg.topic : “StateEvent”
msg.payload : the new state of the selected item
Channel 2:

msg.item : the item’s itemname (not label)
msg.topic : “RawEvent”
msg.payload : raw (unprocessed) event for the selected item

It seems that no topic is assigned.

I have been working on it for a while, and I think I misunderstood the concept of the flow. So I rework my check for present and set homeState like this:

Instead of making multiple comparatives I do them step wise, and the overview of my rule is much better.

[
    {
        "id": "e8e43789.1f1868",
        "type": "comment",
        "z": "1d1f1776.298d19",
        "name": "Open door, if dark, turn on light ",
        "info": "",
        "x": 210,
        "y": 400,
        "wires": []
    },
    {
        "id": "d26a5397.45c9f",
        "type": "openhab2-in",
        "z": "1d1f1776.298d19",
        "name": "",
        "controller": "e6d015f.73ddee8",
        "itemname": "Motion_Sensor_Kitchen_Status",
        "x": 190,
        "y": 480,
        "wires": [
            [
                "855768a7.d1d538"
            ],
            []
        ]
    },
    {
        "id": "ababc116.ab1ff",
        "type": "openhab2-in",
        "z": "1d1f1776.298d19",
        "name": "",
        "controller": "e6d015f.73ddee8",
        "itemname": "Motion_Sensor_Gang_Status",
        "x": 180,
        "y": 540,
        "wires": [
            [
                "855768a7.d1d538"
            ],
            []
        ]
    },
    {
        "id": "811c99f.c8c7368",
        "type": "openhab2-in",
        "z": "1d1f1776.298d19",
        "name": "",
        "controller": "e6d015f.73ddee8",
        "itemname": "Motion_Sensor_Sove_Status",
        "x": 180,
        "y": 600,
        "wires": [
            [
                "855768a7.d1d538"
            ],
            []
        ]
    },
    {
        "id": "6bd234dc.387a7c",
        "type": "openhab2-out",
        "z": "1d1f1776.298d19",
        "name": "",
        "controller": "e6d015f.73ddee8",
        "itemname": "gLights_Kitchen_toggle",
        "topic": "ItemCommand",
        "payload": "ON",
        "x": 1190,
        "y": 460,
        "wires": []
    },
    {
        "id": "862d70cf.1cab4",
        "type": "openhab2-out",
        "z": "1d1f1776.298d19",
        "name": "",
        "controller": "e6d015f.73ddee8",
        "itemname": "gLights_Gang_toggle",
        "topic": "ItemCommand",
        "payload": "ON",
        "x": 1180,
        "y": 500,
        "wires": []
    },
    {
        "id": "e8c32002.0fef4",
        "type": "openhab2-in",
        "z": "1d1f1776.298d19",
        "name": "",
        "controller": "e6d015f.73ddee8",
        "itemname": "Motion_Sensor_Stue_Status",
        "x": 180,
        "y": 660,
        "wires": [
            [
                "855768a7.d1d538"
            ],
            []
        ]
    },
    {
        "id": "855768a7.d1d538",
        "type": "switch",
        "z": "1d1f1776.298d19",
        "name": "Check if Dark",
        "property": "IsDark",
        "propertyType": "global",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "neq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "outputs": 2,
        "x": 500,
        "y": 520,
        "wires": [
            [
                "28caa0ca.37b65",
                "74f28918.1a3158"
            ],
            []
        ]
    },
    {
        "id": "c9346a19.b22a68",
        "type": "openhab2-out",
        "z": "1d1f1776.298d19",
        "name": "",
        "controller": "e6d015f.73ddee8",
        "itemname": "gLights_Stue_toggle",
        "topic": "ItemCommand",
        "payload": "ON",
        "x": 1180,
        "y": 580,
        "wires": []
    },
    {
        "id": "3e60c37a.89b72c",
        "type": "switch",
        "z": "1d1f1776.298d19",
        "name": "",
        "property": "item",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "Motion_Sensor_Kitchen_Status",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "Motion_Sensor_Gang_Status",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "Motion_Sensor_Sove_Status",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "Motion_Sensor_Stue_Status",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "outputs": 4,
        "x": 890,
        "y": 520,
        "wires": [
            [
                "6bd234dc.387a7c"
            ],
            [
                "862d70cf.1cab4"
            ],
            [
                "4de72591.f3810c"
            ],
            [
                "c9346a19.b22a68",
                "103c7ae6.91ffa5"
            ]
        ]
    },
    {
        "id": "28caa0ca.37b65",
        "type": "debug",
        "z": "1d1f1776.298d19",
        "name": "",
        "active": false,
        "console": "false",
        "complete": "false",
        "x": 750,
        "y": 460,
        "wires": []
    },
    {
        "id": "aa9d8bc0.e257a8",
        "type": "comment",
        "z": "1d1f1776.298d19",
        "name": "set color temp to 33 for max lys, set also britness",
        "info": "",
        "x": 1120,
        "y": 380,
        "wires": []
    },
    {
        "id": "74f28918.1a3158",
        "type": "switch",
        "z": "1d1f1776.298d19",
        "name": "Check if Sleeping",
        "property": "IsDark",
        "propertyType": "global",
        "rules": [
            {
                "t": "eq",
                "v": "OFF",
                "vt": "str"
            },
            {
                "t": "neq",
                "v": "OFF",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "outputs": 2,
        "x": 710,
        "y": 520,
        "wires": [
            [
                "3e60c37a.89b72c"
            ],
            []
        ]
    },
    {
        "id": "103c7ae6.91ffa5",
        "type": "openhab2-out",
        "z": "1d1f1776.298d19",
        "name": "Plug_stue_lampe",
        "controller": "e6d015f.73ddee8",
        "itemname": "Plug_stue_lampe",
        "topic": "ItemCommand",
        "payload": "ON",
        "x": 1170,
        "y": 620,
        "wires": []
    },
    {
        "id": "4de72591.f3810c",
        "type": "openhab2-out",
        "z": "1d1f1776.298d19",
        "name": "",
        "controller": "e6d015f.73ddee8",
        "itemname": "gLights_Sove_toggle",
        "topic": "ItemCommand",
        "payload": "ON",
        "x": 1180,
        "y": 540,
        "wires": []
    },
    {
        "id": "50237276.f65c6c",
        "type": "comment",
        "z": "1d1f1776.298d19",
        "name": "TO-DO add auto off and better light",
        "info": "",
        "x": 1060,
        "y": 420,
        "wires": []
    },
    {
        "id": "e6d015f.73ddee8",
        "type": "openhab2-controller",
        "z": "",
        "name": "Openhab",
        "protocol": "http",
        "host": "192.168.1.109",
        "port": "8080",
        "path": "",
        "username": "",
        "password": ""
    }
]
1 Like

Glad you got it to work. I find that simple is usually best with Node-Red. I did find this node that I use sometimes to consolidate my switch checks to a single node - node-red-contrib-match - npm

2 Likes

Nice, that a very nice node! I’ll be sure to use that in the furture:slight_smile: