How to make use of generic 433Mhz sensors?

For devices that do not confirm their state like these switches, you are relying on an assumption that the device is in the state last recorded in HASS.

The best way to improve reliability is to look for devices with separate on / off buttons so you know the intention is to turn off the device (for example). Not a guarantee that it worked but at lest you know your intention.

Single buttons that toggle can get out of sync very easily!

1 Like

@1technophile They are 220V powered, I’m from Europe and here we are using only 2 wires for the lamp switches, so there is only 1 live wire and one wire that is going to the lamp itself, there is no GND

Sorry @ReneTode I don’t have a spare one to open it completely…

with only 1 live wire, how is it 220v powered?
if the ligt is out, there is no power to the switch, but it still needs power to put the switch back on.

so, some kind of powerstorage must be inside the switch.

Do they only send the signal on the event, or do they periodically send the current state? One thing I wasn’t really considering, is if HA gets out of sync when I restart it, or upgrade it or something.

https://www.aliexpress.com/item/High-grade-Wireless-Magnetic-Door-sensor-Window-Open-and-Close-detector-for-Home-Security-alarm-system/32657321054.html

they only send signal on the event. To keep track the state, I created an automation to publish an MQTT topic with retain option when I receive the original topic from the gateway. After that I only focus on the newly created topic for automation and other stuff.

For example…

Automation:

#########################################################

- alias: 'Door Sensor - Back Door Open'
  trigger:
    platform: mqtt
    topic: home/433toMQTT
    payload: 123456789
  action:
    service: mqtt.publish
    data:
      topic: 'home/kitchen/backdoor'
      payload: 'open'
      retain: 'true'

#########################################################

- alias: 'Door Sensor - Back Door Close'
  trigger:
    platform: mqtt
    topic: home/433toMQTT
    payload: 234567891
  action:
    service: mqtt.publish
    data:
      topic: 'home/kitchen/backdoor'
      payload: 'close'
      retain: 'true'
3 Likes

@masterkenobi

Hello, I think I finally found a solution to my problem.
I await your confirmation if this will or will not work.

The idea is to replace my common home switches, for some RF, ie I want to both turn the lights on / off by pressing the switch.

As well as on / off by the home assistant.

My doubts are as follows:
When you press the switch, it issues a command Rf to on and issues an Rf command to off?

If so, I think this will solve my problem and so I can replace all my normal switches, and I can always know their state in HA.

@1technophile, i have a feature request.

Can you make the gateway to publish only a single code when the sensor is triggered? The reason why is some of the sensors send out 10 to 20 same codes in a single burst. This will make the automation in my HA to go crazy and sometimes crashes it. For now, I overcome this by using automation.turn_off and then delay for few seconds before automation.turn_on. For example…

- alias: 'Water Sensor - Backyard'
  initial_state: True
  trigger:
    platform: mqtt
    topic: home/433toMQTT
    payload: 88888888
  action:
    - service: automation.turn_off
      entity_id: automation.water_sensor__backyard
    - service: notify.notify
      data_template:
        title: ""
        message: "It is raining now"
    - delay:
        seconds: 10
    - service: automation.turn_on
      entity_id: automation.water_sensor__backyard

It works but sometimes, my HA would crashed for unknown reason. However, it runs smoothly for few days after I unplug 433toMQTTto433 gateway.

Anyway, even if it is not the reason why my HA crashes, it will be a nice feature to have because less payload means less overhead on my MQTT broker.

@masterkenobi

If you look at some of the sketches for his NodeMCU based gateways, he has some deduping logic. I added some of it in my arduino based version. I am, however, considering moving to a NodeMCU because it has more SRAM that can be used to dedupe more 433 device events.

Look at the isAduplicate function, and supporting functions/variables.

One thing I did notice, on the arduino version at least, if I have 2 devices send at the same time, I get nothing. On rare occasions, I get payload that doesn’t match either of them. I’m not sure if it is something in the RCSwitch, or just a limit of the protocol.

thanks. are you referring to the time_avoid_duplicate variable? I think mine was based on older version and I don’t think it has that option. Anyway, I will try it out soon.

@rhodges

I have uploaded the new sketch to my nodemcu and I am using this; #define time_avoid_duplicate 1 but still receiving multiple same codes :confused:

Yes. You’d need to pull in from that link…

The block of if (mySwitch.available()) inside the loop. It has calls to isAduplicate and storeValue.
The functions getMin, storeValue, and isAduplicate.
The #define time_avoid_duplicate 3000
The variable long ReceivedRF[10][2]

Basically it keeps track of the 10 most recent events (based on the number received from the 433 receiver) and dedupes based on that. The arduino uno version is very memory limited, 2k of SRAM, so you wouldn’t really be able to go more than that.

Hopefully you don’t have more than 10 devices transmitting duplicates during the same 3 second interval.

This evening, or maybe tomorrow evening, I can probably, if @1technophile doesn’t beat me to it, and doesn’t mind, add those functions to the original Arduino Uno version. Are you using that version or the first ESP8266 version?

@rhodges

yes. i have updated the sketch to the latest version and I have changed the time_avoid_duplicate value to 1 millisecond. When the sensor trigger, it still publishes multiple same code to the broker.

I think you need to leave the time_avoid_duplicate high, like 2000 or 3000. I noticed for the door sensors from aliexpress, they keep transmitting as long as you see the light. That is, they push the signal multiple times over 2 or 3 seconds.

The dedupe logic stores the first time it see the signal and then the next time, and the next time, and the next time. The time between the first time and the last time is what the time_avoid_duplicate needs to be.

1 millisecond isn’t near enough. Try between 250 and 3000.

1 Like

ah… now i get it. it is working like how i wish now. thanks! :smile:

1 Like

Help is welcome don’t hesitate to submit a pull request!

How did you manage in the end?

You bought sensors and a receiver? If yes which receiver?

yeah. i managed to build the gateway and integrate all these sensors.

thanks.

I bought 1 hour ago the stuff of this video

Hello, I have RF modules HC-12 that workshop with 433mhz André comunication serial.
I want to work with MQTT.
Can you give me your code?

Hi, which are the advantages/disadvantages of first vs second solution?