On/off button simulator with relay

Hi,

My friend and I built this temperature and humidity controller, which I've been using for the past 3 months, and no problems with the code.

What I realized is that my dehumidifier is too small, so I got a bigger one (the one in the picture). When I plugged into the controller the relay board can't control this dehumidifier. Once it goes off it doesn't come back on. So I investigated and made a bypass to the on/off button (the black cable on the dehumidifier picture), I tried manually (touching one end of the cable with the other end) and it works just fine. So my plan is to remove the varistor, fuse, and socket on the dehumidifier relay, plug the dehumidifier into the wall, and plug these button bypass cables into the relay board. This way I can get the dehumidifier to do what I want automated.

My problem here is that my friend is the actual "engineer" I developed the concept and told him how I think it should operate and he did all the code. The problem is he changed jobs and is loaded with work and says that doesn't have any time to help me out (which I think is bullshit, I think that takes literally 1 minute or even less for someone with his experience) so I'm hoping someone here can help me.

THE CODE:
Funcionamento Desumidificador:

var Sondas = global.get("sondas");
var SetPoints = global.get("configs");
var Estados = global.get("estados");

var humi1 = Sondas["IThumidade"];
var humi2 = Sondas["IBhumidade"];

var SP = SetPoints["DESUsetpoint"];
var DF = SetPoints["DESUdif"];

var humiMedia = ((humi1 + humi2) / 2.0).toFixed(2);
var msg2 = { payload: humiMedia };
var msg3 = { payload: (SP - DF) };

msg.payload = Estados["Desumidificador"];
if(humiMedia > (SP)){
    msg.payload = true;
    //return [msg, msg2, msg3];
}
if(humiMedia <= (SP - DF)){
    msg.payload = false;
    //return [msg, msg2, msg3];
}
return [msg, msg2, msg3];

Status

var Estados = global.get("estados");
var Manuais = global.get("manuais");
var Automatico = global.get("automaticos");

if((msg.payload === true 
    && Estados["Desumidificador"] === false 
    && Automatico["Desumidificador"] === true) 
    || (Manuais["Desumidificador"] === true 
    && Automatico["Desumidificador"] === false
    && Estados["Desumidificador"] === false )){
    msg.payload = "LIGADA";
    msg.color = "#00ff00";
    Estados["Desumidificador"] = true;

    global.set("estados", Estados);
    return msg;
}
if((msg.payload === false 
    && Estados["Desumidificador"] === true 
    && Automatico["Desumidificador"] === true) 
    || (Manuais["Desumidificador"] === false 
    && Automatico["Desumidificador"] === false
    && Estados["Desumidificador"] === true )){
    msg.payload = "DESLIGADA";
    msg.color = "yellow";
    Estados["Desumidificador"] = false;

    global.set("estados", Estados);
    return msg;
}

Relay control

if(msg.payload === "LIGADA"){
    msg.payload = 0;
    return msg;
}
if(msg.payload === "DESLIGADA"){
    msg.payload = 1;
    return msg;
}

Now that you already have an idea of the problem, this is my idea to solve the problem:

  • Plug dehum to the wall
  • Remove varistor, fuse and socket from the relay board
  • Plug the on/off bypass cables instead
  • Change the code on "Relay control"
  • Add a 2s Delay
  • Add another function afterwards called "Relay auto off"

Relay Control (code changed):

if(msg.payload === "LIGADA"){
    msg.payload = 0;
    return msg;
}
if(msg.payload === "DESLIGADA"){
    msg.payload = 0;
    return msg;
}

This goes to a 2 second delay node and the goes to the following node:

Relay auto off (new function node)

if(msg.payload === "LIGADA"){
    msg.payload = 1;
    return msg;
}
if(msg.payload === "DESLIGADA"){
    msg.payload = 1;
    return msg;
}

Do you think this will work? If not, any solutions?

Thanks in advance and happy projects!

Note:
Since the controller is operating 24/7 I don't have time to test a lot of options, otherwise, the temperature and humidity of my room will get too high and too humid. This is why I'm hoping someone here can help me


Don't know the answers without some more thought which I shouldn't be doing while at work!

But I should give the obligatory warnings about this being an open internet forum not advice on the safe hacking of mains-powered hardware. Taking out the fuse sounds like a really bad idea though.

1 Like

So tell me what other info do you need?

I didn't remove anything from my dehumidifier. The only thing I did there was to weld 2 cables to the power button so the relay can control it.

I've put varistors and fuses on my controller because whenever a piece of equipment with a motor went off it would discharge a bit of too much power and mess with my DHT22. Since the dehum is going to be plugged to the wall now this discharge will go to the grid and not messing my sensors.

This are the varistors, fuses and sockets I'm talkinng about.

That all looks very safe :wink:

1 Like

I don’t think you shared enough of your code to figure out the exact control mechanism.

But basically you had and output that used to latch a relay on to provide power.

Now you want to emulate a button press, so I would suggest you put a trigger node between the flow and the node which sends the message to the relay.

Set this to send the appropriate on command and then after 2 seconds send the off command.

Each time your flow wants to interact with the device, it will send an on followed by an off, this will toggle the device state.

You will just need to be careful that the state of the device doesn’t get out of sync with your flow or it would operate the wrong way around :wink: