How to use DIY window/door sensors?

Like usual, in advance I would like to thank all you that offer me such great help every time I have a question.

I am looking to take my gfs setup to the next level, and make it run a house alarm for her. I noticed that on most of her doors I can easily drill from the door frame into the light switch box on the wall, where there is a D1 Min with Tasmota.

So far I’ve got the front door and the back door set up. Running a US1881 hall sensor on the front door, and a reed switch on the back door. The reed switches in theory are much easier to set up, but BOY ARE THEY FRAGILE! I busted like 4 of them trying to set it up inside the hole I made on the door frame.

First thing that I learned was that if I just added it as another switch to the D1 Mini, but didn’t assign a relay to it, it would actually switch the number 1 relay. For example, in the back door tasmota I had relay1 with switch 1 and relay2 with switch 2. I added switch 3 as the input of the door sensor, and when opening and closing the door it would toggle the relay1.

Recently I had set up a tasmota with extra switches, and using rules I get the switches to control the right relays on a totally different tasmota. So to stop the door from triggering the relays I set up a rule for it to send a command to a device that doesn’t exist.

So finally I get to my question. How can I now integrate this sensor/switch onto HomeAssistant to know when the doors are open or closed? I am guessing is a two step solution and I already have the 2nd step. First I need to create something on home assistant, like a binary sensor, then the 2nd step would be to set a rule on the tasmota to update binary sensor state via mqtt.

So it seem I’ve answer my own question

binary_sensor:
  - platform: mqtt
    name: "Puerta Porton"
    state_topic: "tasmota_553BF0/cmnd/POWER4"
    payload_on: "ON"
    payload_off: "OFF"
    device_class: door

On the Yaml file. Is there a “new” way of doing it, since I know many things are being done through integrations.

Like your thinking bro

think you missing some in tasmota setting

I have

which has a wall push button on gpio14

which I has set to
switchmode1 5

cause if i change the
to
image

it does not switch the light on/off and console shows this

03:56:17 MQT: cmnd/SONOFF10/POWER2 = ON
03:56:17 MQT: stat/SONOFF10/RESULT = {"Command":"Unknown"}
03:56:17 MQT: cmnd/SONOFF10/POWER2 = ON
03:56:17 MQT: stat/SONOFF10/RESULT = {"Command":"Unknown"}

I have tasmota door a D1 mini

D6 is the reed switch

so when the door open/close

NOTE: switchmode

https://tasmota.github.io/docs/Buttons-and-Switches/#switchmode

I get this

04:04:06 MQT: stat/H_Cupboard/RESULT = {"POWER":"ON"}
04:04:06 MQT: stat/H_Cupboard/POWER = ON
04:04:11 MQT: stat/H_Cupboard/RESULT = {"POWER":"OFF"}
04:04:11 MQT: stat/H_Cupboard/POWER = OFF

ON been open
OFF been closed

now HA in the binarysensor i have

  - platform: mqtt    
    name: "Cupboard Door"
    state_topic: "stat/H_Cupboard/POWER"
    qos: 2
    payload_on: "ON"
    payload_off: "OFF"
    device_class: door

closed
image

open
image

BUT in automation we look at then as a ON/OFF

so

- id: Hall Light On Cupboard Open
  alias: Hall Light On Cupboard/linen Open
  initial_state: true
  trigger:
  - entity_id: 
    - binary_sensor.cupboard_door
    - binary_sensor.linen_door
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: light.hallway
    state: 'off'
  - condition: state
    entity_id: sensor.day_night
    state: Night
  action:
  - data:
      entity_id: light.hallway
    service: light.turn_on

now when I open the cupboard door the hall light come on

now the OFF bit

 id: Hall Light On Cupboard Closed
  alias: Hall Light Off Cupboard/linen Closed
  initial_state: true
  trigger:
  - entity_id: 
    - binary_sensor.cupboard_door
    - binary_sensor.linen_door
    platform: state
    to: 'off'
  condition:
  - condition: state
    entity_id: input_boolean.hall_light
    state: 'on'
  action:
  - delay: 00:00:03
  - data:
      entity_id: light.hallway
    service: light.turn_off
  - data:
      entity_id: input_boolean.hall_light
    service: input_boolean.turn_off

Put the delay in so you get time to walk out of the hall

you answer your question as i was righting this.

there more than one way to skin a cat as long as it does what you want its the right way.

also I went down this track

image

NO drill hole in walls LOL

1 Like

Thank you for such detailed answer.

First thing I want to bring up for anyone that might find this thread for help is that the command sequence might be different depending if you are using autodiscovery or not. For example, "state_topic: “stat/H_Cupboard/POWER” since I am using autodiscovery in my setup it would be "state_topic: “H_Cupboard/stat/POWER”

Also, on your door D1 mini, you show a picture of your settings. You put a blue mark by D8 and then you say that is where you have your reed switch connected. I don’t think that is correct. Relay’s are outputs not inputs. I am guessing that the reed switch is actually connected to D6, Switch1, and I will also venture out to say that you don’t really have a relay connected at all.

D8 can be a tricky pin to work with, one better not to use if you don’t have to. GPIO15 (D8) is pulled to ground, and if pull high at boot time it won’t boot. I guess if you had no other option, you could set up a relay there, since you would be using the pin as an output, and there isn’t a reason why the relay itself would pull the pin to high during boot.

I haven’t done any playing around with the 01 Sonoff Basic module. All of my tasmotas are running the generic module.

On the generic module, I know for a fact that if you only have one relay, and multiple switches they will all control the one relay. The tasmota by the front door has one relay to control the front porch lights, 4 switches (1 to control front porch, 2 to control living room lights on another tasmota, 3 to control the living room fan on another tasmota, 4 the door sensor/switch), and finally an ultrasonic sensor which I am having problems with as well (totally diff subject).

I has all 4 switches set to switchmode 5. All switches were turning the front porch lights on and off until I created the rules for them to control the right thing I wanted. In fact I found this flaw before and used it to my advantage. I have one tasmota controlling kitchen and stairs on the bottom end, and stairs and upstairs hallway on the upstairs end. Basically 3 relays, 4 switches. First I tried to connect the two stairs switches to the same pin, that didn’t work. I then tried to list two different pins with the same switch1, but that didn’t work. My last attempt was going to be to make one switch4 then create a rule for switch4 to toggle switch1, but I noticed that without creating the rule, switch4 automatically controls switch1.

I mostly use touch sensor for my switches, and based on some instructions I found I set it up as switchmode 5. I am not sure what the “hold” actually does, but it did throw me for a small loop today. Seems switchmode 3 and 4 would also work, and they wouldn’t have the HOLD after long press.

“NO drill hole in walls LOL”, actually the way I did it makes for a MUCH cleaner looking install. There are no boxes, cables or anything showing. Those Xiaomi sensors are probably much easier/faster to install, but my way ends up being MUCH cheaper, doesn’t require worrying about batteries, and did I mention there isn’t any device or wires showing? :slight_smile:

1 Like

well put bro

the way I use the hold is
have a sensor that expire after 1 sec

  - platform: mqtt
    name: "Garge Light"
    state_topic: "cmnd/SONOFF5/POWER1"
    qos: 1
    expire_after: 1
- id: 'hold garge light'
  alias: Hold Garge Light
  initial_state: true
  trigger:
  - entity_id: sensor.garge_light
    platform: state
    to: 'HOLD'
  action:
  - data:
      entity_id: light.workshop
    service: light.toggle

that save me 5 steps LOL

I was actually just reading your HOLD post. I had heard about double tapping and triple tapping to do more things. I had never heard of the HOLD. I accidentally put my tasmota on HOLD and I didn’t know how to stop it. In fact I forget what I did to clear it.

Myle, you actually got me interested in doing a similar set up.

I would like to be able to long press two switches (buttons) at the same time, and when both switches are on hold, it would trigger an automation to turn disarm the alarm.

I haven’t been able to find much info. I understand I have to put them as switchmode 5 (or 6) for the long press to be active and be able to go onto hold. What I couldn’t figure out was how to get them out of the “hold” state.

You mentioned you set up your binary sensor to expire after 1 second, does that take the tasmota switch out of hold?

the

expire_after: 1

puts the sensor into “unavailable” after 1 sec

image

tasmota switch does not go on hold it just send the “hold” over MQTT

image

like the disarm the alarm options nice thinking bro

I will check again tomorrow. Of course my girlfriend picked the most difficult switch I have to set up the two button trick.

I am going by memory here, but switch1 controls a real relay attached to the d1 mini, and switch3 controls a remote relay. When I put both of those switches on HOLD with a long press, on the console it keep saying HOLD. Once on HOLD if I pressed switch1 the right relay would toggle on and off normally, but then it would end with showing the HOLD on the console again. On switch 3, it would toggle the remote relay, but a few seconds later it would toggle back. If I turned remote relay on with HomeAssistant it would remain in the new state.

Basically, when I put them on HOLD each time I would use the switch, it would do something, then throw out the word HOLD on the screen again. Only way I figured out how to get it to stop doing it, was to do switchmode to 3, then back to 5, and it was all back to normal. Remember how I had mentioned I liked using switchmode 3 better, since I had issues with getting out of HOLD once it was on HOLD.

This is my console output

18:55:29 RUL: SWITCH2#STATE performs "publish SalaMiriam/cmnd/POWER2 TOGGLE"
18:55:29 MQT: SalaMiriam/cmnd/POWER2 = TOGGLE
18:55:29 MQT: stat/tasmota_553BF0/SWITCH2T = {"TRIG":"HOLD"}
18:55:57 RUL: SWITCH2#STATE performs "publish SalaMiriam/cmnd/POWER2 TOGGLE"
18:55:57 MQT: SalaMiriam/cmnd/POWER2 = TOGGLE
18:55:57 MQT: stat/tasmota_553BF0/SWITCH2T = {"TRIG":"ON"}
18:56:02 RUL: SWITCH2#STATE performs "publish SalaMiriam/cmnd/POWER2 TOGGLE"
18:56:02 MQT: SalaMiriam/cmnd/POWER2 = TOGGLE
18:56:02 MQT: stat/tasmota_553BF0/SWITCH2T = {"TRIG":"HOLD"}
18:56:22 RUL: SWITCH2#STATE performs "publish SalaMiriam/cmnd/POWER2 TOGGLE"
18:56:22 MQT: SalaMiriam/cmnd/POWER2 = TOGGLE
18:56:22 MQT: stat/tasmota_553BF0/SWITCH2T = {"TRIG":"HOLD"}
18:56:51 RUL: SWITCH2#STATE performs "publish SalaMiriam/cmnd/POWER2 TOGGLE"
18:56:51 MQT: SalaMiriam/cmnd/POWER2 = TOGGLE
18:56:51 MQT: stat/tasmota_553BF0/SWITCH2T = {"TRIG":"HOLD"}
18:57:29 RUL: SWITCH2#STATE performs "publish SalaMiriam/cmnd/POWER2 TOGGLE"
18:57:29 MQT: SalaMiriam/cmnd/POWER2 = TOGGLE
18:57:29 MQT: stat/tasmota_553BF0/SWITCH2T = {"TRIG":"HOLD"}
18:58:35 MQT: stat/tasmota_553BF0/SWITCH1T = {"TRIG":"HOLD"}
18:58:41 MQT: stat/tasmota_553BF0/SWITCH1T = {"TRIG":"HOLD"}
18:58:45 MQT: stat/tasmota_553BF0/SWITCH1T = {"TRIG":"ON"}
18:58:45 MQT: tele/tasmota_553BF0/STATE = {"Time":"2020-07-17T18:58:45","Uptime":"0T17:23:39","UptimeSec":62619,"Heap":21,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER1":"OFF","POWER2":"ON","POWER3":"ON","POWER4":"ON","Wifi":{"AP":1,"SSId":"Miriam","BSSId":"8C:04:FF:B6:A9:F1","Channel":3,"RSSI":100,"Signal":-45,"LinkCount":1,"Downtime":"0T00:00:07"}}
18:58:45 MQT: stat/tasmota_553BF0/RESULT = {"POWER1":"OFF"}
18:58:45 MQT: stat/tasmota_553BF0/POWER1 = OFF
18:58:50 MQT: stat/tasmota_553BF0/SWITCH1T = {"TRIG":"HOLD"}
18:58:58 MQT: stat/tasmota_553BF0/SWITCH1T = {"TRIG":"ON"}
18:58:58 MQT: tele/tasmota_553BF0/STATE = {"Time":"2020-07-17T18:58:58","Uptime":"0T17:23:52","UptimeSec":62632,"Heap":21,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER1":"ON","POWER2":"ON","POWER3":"ON","POWER4":"ON","Wifi":{"AP":1,"SSId":"Miriam","BSSId":"8C:04:FF:B6:A9:F1","Channel":3,"RSSI":74,"Signal":-63,"LinkCount":1,"Downtime":"0T00:00:07"}}
18:58:58 MQT: stat/tasmota_553BF0/RESULT = {"POWER1":"ON"}
18:58:58 MQT: stat/tasmota_553BF0/POWER1 = ON
18:59:03 MQT: stat/tasmota_553BF0/SWITCH1T = {"TRIG":"HOLD"}

So switches1 and 2 I did a long press and put them on “hold”, but now each time I toggle the switch I does the correct toggle, but then throws {“TRIG”:“HOLD”}

have you got sensor set like this

  - platform: mqtt
    name: "SWITCH1T TRIG"
    state_topic: "stat/tasmota_553BF0/SWITCH1T" # <======== the topic to look at
    value_template: "{{value_json.TRIG }}"  #< ========= read the json TRIG value
    qos: 1
    expire_after: 1

now sensor.switch1t_trig shoould show you the HOLD and then go unavailable

then write the the automation to watch the trigger of the above sensor

Will give that a try, but on your setup, the button that you long press to activate other function, do you have it set as a button or as a switch?

switch and set it with the switchmode options

Myle! I finally figured it out (well the main problem).

The particular touch sensor that I am using, on its “rest” state (not pressed) is pulling to ground. That is why when ever I thought I was putting it on “HOLD” it was actually putting itself on HOLD, and if set at as button, it would trigger the “reset” feature.

Turns out I have to set them up as switchxi or buttonxi and that gives me the outcome you are getting. One long press, creates one HOLD status.

Tomorrow I get to play with the rules for switches, or the setup for buttons.