433toMQTTto433 Bidirectional Arduino Gateway

Don’t think it is hard, If I find half a day in the following months I could try to do it.

Dang! It’s like he was reading my mind!

I was looking into an ir remote arduino next…

:slight_smile:

Yeah, it is logical to combine those two.

Why not throw some sensors like DHT22 into the circuitry as well? It would be awesome if it can publish the temperature and humidity to the MQTT as well.

I have two DHT11 currently on my circuit, I added also a siren, and planning to add an rgb led strip.

Here is the code to adapt for the DHT:

#include "DHT.h"

#define HUM1   "home/sensors/box/hum"
#define TEMP1  "home/sensors/box/temp"
#define HUM2   "home/sensors/living/hum"
#define TEMP2  "home/sensors/living/temp"
#define VOLT   "home/sensors/voltage"

// add this line into the loop method
TempAndHumAndVolt(); // send local data of temperature and and voltage humidity

 void TempAndHumAndVolt(){
      if (millis() > (time1 + 33300)) {//retriving value of temperature and humidity of the box from DHT every xUL, must not be a multiple of previous value to avoid concurrency between sensors
        time1 = millis();
        // Reading temperature or humidity takes about 250 milliseconds!
        // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
        float h = dht.readHumidity();
        // Read temperature as Celsius (the default)
        float t = dht.readTemperature(); 
        // Check if any reads failed and exit early (to try again).
        if (isnan(h) || isnan(t)) {
          trc("Failed to read from DHT sensor!");
        }else{
          sendMQTT(HUM1,String(h));
          sendMQTT(TEMP1,String(t));
        }
      }
      if (millis() > (time2 + 3600000)) {
        time2 = millis();
        // Reading temperature or humidity takes about 250 milliseconds!
        // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
        float h2 = dht2.readHumidity();
        // Read temperature as Celsius (the default)
        float t2 = dht2.readTemperature(); 
        // Check if any reads failed and exit early (to try again).
        if (isnan(h2) || isnan(t2)) {
          trc("Failed to read from DHT2 sensor!");
        }else{
          sendMQTT(HUM2,String(h2));
          sendMQTT(TEMP2,String(t2));
        }
        //retriving value of voltage of the box
          int val = 0; 
          val = analogRead(4);
          trc(String(val));
          sendMQTT(VOLT,String(val*0.0194));
      }
    }

Here is it:

@Partybug

Not close to Seymour, but would be happy if I could mess with my own 433 devices! lol

Question: the state_topic: “home/433toMQTT”, how do you get that particular data?
I have a node-red setup with 433 and Im trying to have HA send 433 binary codes through HA to MQTT to control my 433 (doorbell, fan, etc)

I know it may sounds like a stupid question but I tried something similar:

Switch:

  • platform: mqtt
    name: “DoorBell”
    state_topic: “home/433toMQTT”…???
    command_topic: “home/MQTTto433/”
    payload_on: “my binary code here”
    payload_off: “my other binary code here”
    optimistic: true
    retain: true

Does it look ok?

@aelg305,
The command topic is the MQTT topic that HA uses to send codes to the device.
To answer your question, the state_topic is the mqtt topic to listen to data from an external source which in my case is the remote control that came with my switch. So if your fan has a remote control, you press the button on the remote and the 433toMQTTto433 gateway would “hear” that remote too (like the fan did) and send the MQTT traffic to HA to change the state of the fan so that HA in synch with the fan’s status.

I’m not familiar with node-red, but you didn’t mention your MQTT broker which is needed to “operate” the traffic for MQTT topics. I use Mosquitto (an MQTT broker) on the same Pi with HA. After Mosquitto is setup and you can listen and send mqtt manually, don’t forget to add this information to HA with this configuration.

mqtt:
broker: 192.168.xxx.xxx
port: 1883 (match to yours)
client_id: xxxx (mine is named hass)
keepalive: 60

I found this website which could be helpful to you: https://www.rs-online.com/designspark/building-distributed-node-red-applications-with-mqtt

And if your ever in Seymour Indiana…

1 Like

@Partybug i know you have a some 433 mhz etekcity, but i have a question for you.
i have a similar etekcity, but the other debrand.
its has one phisically button, its possible when i press the phisically button , HA knows the state of etekcity?

got the topics working:
using node red, I used the “debug” function.
To answer the question about the broker: mosquitto as well, setup similar to yours.

Im able now to send messages from the hass “set state” page manually, working now on getting the same results with automation, etc.

Thanks for the article…it did help

1 Like

How many devices do you think you could safely proxy thru an arduino? What about multiple events coming in at the same time (or when it is pushing the message to mqtt)?

I have 15 devices emitting by 433mhz running without problem. Difficult to say what could be the maximum quantity that could pass to the arduino, a load test should be done. I 'm quite confident If I increase the number of sensor to 20-30 it will be ok.
About multiple events coming at the same time, before having a bottleneck with MQTT you could have a wave superposition in 433mhz.
I did some test with two remote control sending two different code, if I press the two buttons at the same time the signal is not caught. If I introduce a little gap less than 0,5s the both signals are read. Indeed my sensors are not able to receive an acknowledgement so as to know when the message is caught by the gateway. By the way not able to repeat in case of a message not received.
For my home automation this constraint is not disturbing me I don’t need to have acknowledgement, I prefer to have several cheap sensors compared to one with acknowledgement more expensive.

Regarding the other direction pushing the message from MQTT to 433mhz it is working well, the gateway is not pushing signals at the same time. I have some scene that require several plugs to be turned ON and they are turned ON one by one.

Thanks for the feedback.

I had planned to start with those inexpensive door/window sensors. I have 18 windows that I’d put them on, and maybe some doors. The windows will be such a rare event, that I don’t expect much traffic from them.

I was thinking, however, if I expected it out, like temperature/humidity, motion, etc.

I have a Pi I was going to use for another purpose and I thought, instead of an Arduino, I could run this on the Pi. I did hear there was a bit of an issue with the Pi feeding back noise.

I am waffling between Arduino and Pi. I considered spending the money for the setup over at pilight that includes a filter (since I don’t feel like putting it together myself), but they seem to be out of the filters at the moment.

You have also the esp8266 gateway solution:

It’s a quite simple solution.

I have never tested to connect directly the rf receiver and emitter to the pi, mainly due to the fact that I’m handling some emergency function at the arduino gateway level for reliability concerns (siren of the alarm), and i don’t want to deport that to the pi

PS: I have also 433mhz motion, temp , hum as sensors and also smoke detectors

I thought about that too. In a nutshell, the “other” stuff I was going to put on it, is 3 switch inputs on GPIO pins and also run a bluetooth ibeacon. It is the ibeacon part that trips up the arduino. There are solutions, but they seem rather expensive really. I already have the Pi3 and it has bluetooth. And I wanted to wire the network.

I wonder if maybe the ESP32 would work. It will also have bluetooth and ble. I’ll do some reading on it. It wouldn’t satisfy the wired requirement, but I don’t really need it wired. It would be nice, but oh well.

On the paper ESP32 would be perfect, but I’m not sure that there is sufficient ressources in the net to do the job with it unless you are a specialist.

Why not combining the approaches, a pi for HA, the ibeacon detection and your switch and an esp8266 or arduino for the 433mhz communications?

Yeah, I agree. I only spent about 30 seconds looking at the ESP32 before I posted.

I will probably do something like that. I actually have a NUC that I’m running HA on, and it has bluetooth in it as well. A lot of options. The big question and and back on track of the thread, is that, the Arduino will probably suffice for the type of 433 traffic I will have in the foreseeable future.

can you show me whats smoke, humity and temperature you use? its are rf too?

Smoke:
http://www.banggood.com/433MHZ-Home-Security-System-Wireless-Smoke-Detector-Fire-Alarm-p-967105.html

For hum and temp they are home made:

I don’t have smoke, just temperature and humidity. I am using (before I found HA) the tags from wireless tags. I’ve had them for a while now. I had to write a Kumo app to post the changes into HA.

http://wirelesstag.net/

I wouldn’t really recommend them. They aren’t much cheaper than some of the zwave solutions (and more than some others).

It was a bit of effort to get them in HA.

1 Like