433toMQTTto433 Bidirectional Arduino Gateway

*Not sure if this is the right forum

Here is what I built:

I did this for two reasons: 1. A gateway to control the cheap 433mhz Etekcity remotes from Hass and 2. To have the ability to “report” back to Hass when a user pushes the button on the remote.

I currently enjoy controlling the switches from Hass via MQTT, but I don’t know how to get Hass to listen to a MQTT topic (home/433toMQTT) to change the status of the switch.

First hurdle is that the MQTT message going back to Hass is the code being sent by the remote. It’s possible to alter the code on the arduino to “interpret” this data to determine a better response to Hass. But does Hass have the ability to listen to the topic and change the switch to match?

Please forgive me if this is silly question. I’ve been using Hass for about a couple months…

6 Likes

nice project, but it reminds me of myselve when i started.
i got a lot off things working and figured out which were already out there :wink:

already seen mysensors?

if you use mysensors and the rcswitch lib together then you have the mysensors gateway.
advantage from that is that you can use lots of arduinos after that connecting to your gateway.
Hass has already a complete mysensors part with usb, wifi, ethernet and mqtt support so you should have not much problems there to create bidirectional communication with hass.

You can also use the pilight component of home assistant to listen to your Etekcity remote. No need to do this via MQTT. See e.g. this blog post how to setup pilight with your remote.

how do you know if he has a RPI at all? he didnt say that he has one
and if he has one, how do you know he wants to transmit at the same place as where he has his RPI?
maybe he wants his transmitter at a place which cant be reached with the RPI.

so there are lots of things why MQTT might be needed.

True, I misread Arduino for RPi. What I said is not possible with an Arduino.

i have a RPI and lots of arduinos, still i dont use pilight because it doesnt give me what i want. :wink:

In OpenHab you can add a mapping file to adress the conversion between the values that are coming from the gateway remote and the corresponding switch state. In home assistant you can search maybe about templates and use the state topic when configuring your switch.
These ideas are just tracks as I don’t have HA i m not able to test.

Regards

I have read about MySensors but I’m not sure they have the same capability of responding back to Home Assistant via an MQTT topic to report that the status changed outside of HA (like a remote).

I just switched to a Raspberry Pi with an AIO install from a Linux Mint Computer to help with zwave devices… That’s another story… Is that an RPI?

I am trying to get the alarmdotcom platform to work (again another story) but I noticed that the MQTT Alarm Control Panel actually listens to a topic to do a static change… so it’s possible for HA to listen to a topic and do what I want… Maybe I can modify that?.. So it could also be possible to make the Etekcity remotes “smart” this way by sending a status via a topic…

Again, I’m a newbie but thanks for allowing me to talk out loud. :slight_smile:

yeah, RPI is an raspberry :wink:

mysensors has 2 way communication possible.
you can make an arduino wo listens to remote and tell HA to change the setting, as well as that you can use HA to change the setting and send it to the arduino who then makes an action.

i have quite a few cheap (old) 433 mhz switches which i control with HA through mysensors.
at the same time i have arduinos with relays that i control in the same way.
i have quite a few arduinos with temperature, light, motion and humidity sensors, and i have automations based on those to control my cheap switches, all trough mysensors.

i dont know what you mean by “a topic” if you mean a file then thats possible.

topic as in MQTT topic. Thanks ReneTode! Looks like I’ll be doing some more reading on it. I’ll definitely be switching to mysensors since it can relay the remote info back to HA. I don’t want to reinvent the wheel…

i have reinvented quite a few wheels myselve :wink:

i had made my own communication protocol and had made my own frontend before i came to mysensors and HA :wink:

but now i love both (almost all of the time :wink: ) and they control my house. arduinos control my heating devices, my lights, my irrigation, my aquariums, and more. :slight_smile:

1 Like

OOOOKAAAY… Thanks to all of you for your input!!

In an earlier post with ReneTode, I stated I was going to switch over to mysensors. Well I was looking into that today and was trying to figure out which sensor to make - it seems all the info on the website is about the gateway and not much on each sensor…

Anyway… I went back through the forum here looking for the sensor and noticed that 1technophile had also posted. (I think he uses OpenHab) So I re-read what he had said since he invented the 433toMQTTto433 Gateway that I’m currently using. He stated “In home assistant you can search maybe about templates and use the state topic when configuring your switch.”

So I took another look at templates which got me looking at the MQTT switch component… Turns out I didn’t have this configured correctly to begin with. I added “state_topic” for Hass to “listen” to the remotes. My mistake before was not adding the “optimistic: true” which is what makes it work.

Here is the configuration that works. And I didn’t change the code just in case your in Seymour Indiana and want to mess with my office fan. (fun!)

Switch:

  • platform: mqtt
    name: “Office Fan”
    state_topic: “home/433toMQTT”
    command_topic: “home/MQTTto433/”
    payload_on: “1382147”
    payload_off: “1382156”
    optimistic: true
    retain: true

(sorry I can’t get the spacing right here.)
Thanks to everyone for helping!

4 Likes

Great to heard that it works and thanks for sharing your config!

I wonder how hard would it be to make 433toMQTTto433 Gateway hardware to also host an IR emitter/receiver. I had this dual 433/IR setup on RPi2 working, but in stateless mode (not remembering what status a switch is in).

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: