How to make use of generic 433Mhz sensors?

but that switch needs how many wires? my standard switch only has two wires.

other question: when you pressed the button phisically the home assistand knows the state? if is turned on or turned off?

i I thought of another alternative using this:

Replaced my normal switch and attached this command to the wall.

So the home assistant always knew the state of my lamp whether it was on or off.

Both if I command by the home assistant, but also if I command physically by pressing the button on the wall.

1 Like

that is more pretty solution, and more cheaps switchs
but i need to know if i pressed phisically button, if home assistant knows the state of swith, if is turned on or turned off
https://pt.aliexpress.com/item/Crystal-Glass-Panel-smart-Switch-EU1gang1-way-Wall-Switch-110-240V-Remote-Touch-Switch-Screen-Wall/32754699726.html?spm=2114.02010208.3.72.qnPEFG&ws_ab_test=searchweb0_0,searchweb201602_2_10065_10068_10084_10083_10080_10082_10081_10060_10061_10062_10056_10055_10037_10054_10059_10032_10099_10078_10079_10077_426_10103_10073_10102_10096_10052_10050_10051,searchweb201603_1&btsid=5c54e3b7-21b8-4f14-9df5-0fabc63a0ae4

it is 433 mhz.
so it sends a code you an use in hass to change states.
off course it is possible that hass misses a state change and will be in the wrong state.

@ReneTode still about rf switch sensor… when press the phisically button HA knows if is turn on or off?

if there is no interference and you configured HA the right way, yeah that could be possible.

1 Like

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