Sonoff mini @ node red - switch state

Hi people,

I just moved over from using Openhab to HassIO and so far i’m not regretting it.

Now that my hassIO is up and running i’m starting with Node Red automations.

I want to switch on my kitchen lights whenever one of the two door sensors (Xiaomi Aqara) gets triggerd. That works fine but, the light’s that get turned on/off are tasmotized soniff mini’s.

I want to be able to override the OFF command from the Xiaomi if the switch was turned on to prevent my kitchen lights from turning off when light is needed.

Currently i’ve got Setoption 19 (autodetect for HassIO) and SetOption30 to ON (force detect as light) enabled.

I’m using HassOS 3.8 without specifying the sonoffs in a yaml so purely using the automatic detected functions.

[
    {
        "id": "95881be2.4741e8",
        "type": "tab",
        "label": "Keuken + deursensoren",
        "disabled": false,
        "info": ""
    },
    {
        "id": "4f8c26c3.825008",
        "type": "server-state-changed",
        "z": "95881be2.4741e8",
        "name": "Achterdeur",
        "server": "586fefcc.a0fab",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "binary_sensor.deursensor_achterdeur_contact",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "x": 100,
        "y": 100,
        "wires": [
            [
                "28ed5a5e.510816"
            ]
        ]
    },
    {
        "id": "8c525002.e7b94",
        "type": "server-state-changed",
        "z": "95881be2.4741e8",
        "name": "Hal deur",
        "server": "586fefcc.a0fab",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "binary_sensor.deursensor_hal_contact",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "x": 100,
        "y": 160,
        "wires": [
            [
                "28ed5a5e.510816"
            ]
        ]
    },
    {
        "id": "36394278.6c894e",
        "type": "api-call-service",
        "z": "95881be2.4741e8",
        "name": "Keuken aan",
        "server": "586fefcc.a0fab",
        "version": 1,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_on",
        "entityId": "light.mini_2, light.keuken, light.mini_diy_3",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 990,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "87153264.00496",
        "type": "api-call-service",
        "z": "95881be2.4741e8",
        "name": "Keuken uit",
        "server": "586fefcc.a0fab",
        "version": 1,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_off",
        "entityId": "light.mini_2, light.keuken, light.mini_diy_3",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 990,
        "y": 140,
        "wires": [
            []
        ]
    },
    {
        "id": "28ed5a5e.510816",
        "type": "switch",
        "z": "95881be2.4741e8",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "on",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "off",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 360,
        "y": 120,
        "wires": [
            [
                "36394278.6c894e"
            ],
            [
                "59f2758a.abe3cc"
            ]
        ]
    },
    {
        "id": "59f2758a.abe3cc",
        "type": "delay",
        "z": "95881be2.4741e8",
        "name": "",
        "pauseType": "delay",
        "timeout": "2",
        "timeoutUnits": "minutes",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 820,
        "y": 140,
        "wires": [
            [
                "87153264.00496"
            ]
        ]
    },
    {
        "id": "586fefcc.a0fab",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "legacy": false,
        "hassio": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true
    }
]

I’m sure it’s because i’m realtively new to Hass.io and Node red but can someone point me in the right direction?

Well can you see the state of the wall switch in HA
If no
Check states page
Or use a debug node full msg object connect to a state change node for the light.
If it’s not on there login to the mini an look at the console for what mqtt message is given when it used.

I’m confused. Are you saying you need help in getting your sonoff switches into HA or that you want help with an automation.

If the automation, what are you using to manually turn the lights on and off?

My sonoffs get discovered in HA, that’s not the problem. The problem is the automation in Node red OR even the switchmode in Tasmota.

I can see the states of the switch in HA. But strangely enough when i flip the switch, the state changes and the light goes on/off. But when i change the state in HASS, the switch state of the S1 & S2 switch don’t change. So it occurs that the fysical switch in my wall is powered ON and the lights are off and vice versa

The sonoff mini’s s1 and s2 are just 1 contact switch.
So are they attributes of the mini or separate binary sensors.

image

this is what Homeassistant auto-detects from the Home-mini

Sorry i only have Shelly’s so i’m going to be assuming with the Sonoff mini tell me if im wrong
light is light
Button 1 is just the external button on the mini
switch 1 is the s1/s2 which is a switch toggle or do you have it as momentary switch
status is device status
switch ? is
let me know the above
so to clear what you want to do is
used switch to turn on lights motion trigger off diabled
didn’t use switch to turn lights on motion trigger off enabled
now can i ask do the sensors pick you up before you get a chance to turn on the switch

I’m off to bed but here is an update without the control break
added only during sunset and sunrise
added reset delay if motion detected again during 2m delay

The sensors are door/window sensors.
It seems that with Tasmota i can change switch states and force HA to see the sonoff-mini as a light in stead of a switch. I’m gonna troubleshoot this first and maybe start from scratch.

it already is a light
light.mini_2

Just don’t pass the off state out of the node. Set it to be only if ON and that will solve your problem without messing with the Sonoff.