Page 1 of 1

use of switches to manage lights in the house

Posted: 25 Sep 2018, 15:40
by marci
Hello,

I'm using ESP8266 to mange sensors and light in my new house under remodeling. All the lighting and sensors are managed directly by batteries powered by Solar. So the 220v is now only in the power plugs. Everything else is DC low voltage.

I thought the manage of lights on-off was very trivial and I didn't spend much time during all the testing I did in the past months .... but it is not really true.

So my configuration at this moment is to have few central controllers (with one MCP23017) that is managing the relays and the majority of the switches. 8 PINs of the MCP manage a 8 port relays board, the remaining 8 on the MCP plus the remaining on the controller do 10 max switches. The remaining 2 position in the Tasks ( 12 positions is really too few ....) is for 2 dummy devices (see below)
Each relay has a position in dummy device so I can then switch them on and off based on the dummy value ..

Code: Select all

on sw13#1 do
 event,switchgo1
endon

on sw14#1 do
 event,switch-go2
endon

// more for all the switches calling the right relay

on switch-go1 do
 if [dummy#d1]=0
	MCPGPIO,2,1
	TaskValueSet,12,1,1            
	publish /L1,1
	else
	MCPGPIO,2,0
	TaskValueSet,12,1,0
	publish /L1,0
 endif
endon

on switch-go2 do
 if [dummy#d2]=0
	MCPGPIO,3,1
	TaskValueSet,12,2,1
	publish /L2,1
	else
	MCPGPIO,3,0
	TaskValueSet,12,2,0
	publish /L2,0
 endif
endon
// more for all the relays
And everything goes pretty well. The switch on and off is almost instantaneous.

THE ISSUE COMES WHEN YOU HAVE SWITCHES ON OTHER CONTROLLERS

if I have a switch on a different controller I have to remotely call the function switch-goX on the master controller.
My first try was to by Node-red and do an http call like http://192.168.1.185/control?cmd=event,switch-go1. The reaction was slow and very variable. In some case it could take 10seconds ... Not accettable

I tryed the UDP connection like sendTo 31,event,switch-go1 (obviously after enabling the UDP port .... and I figured out this works even without the P2P controller enabled) But I had more or less the same result. Benefits we could do everything without Node-red

And finally I worked on MQTT commnds. If the main node was NODE1 I published to NODE1/cmd the message event,switch-go1

Code: Select all

on sw13#1 do
 publish NODE1/cmd,event,switchgo1
endon
And I more or less I had the same issue. The switch was happening but the delay was going from nothing to 10 seconds.

Any idea on how to solve the issue. There is some trick that I miss ?

Tks for the help,
Marcello

Re: use of switches to manage lights in the house

Posted: 26 Sep 2018, 10:18
by dynamicdave
Not too sure of your exact set-up, but you mention Node-RED, so I assume you have a Raspberry Pi or some other platform running Node-RED and MQTT.

What I would do ( I have a number of WeMos Di Minis - ESP8266-based devices in my home) is set each ESP8266 to publish to a MQTT broker.

In my setup I publish messages like... /node32/switch_1,0 <<- where 0 is the switch state, so it could be 1 rather than 0.
So the message is made up of the node reference, switch reference and its state.
Then in Node-RED I have a "flow" that performs the control-system processing.
i.e. checking node states against some predescribed situation.
The "flow" sends commands (via MQTT) back to the appropriate pin on the WeMos D1 Mini GPIO to operate a relay, etc.

Hope this helps.

Regards David

PS:
You can leave off the "leading slash" so the MQTT format matches convention.

i.e. node32/switch_1,0

Re: use of switches to manage lights in the house

Posted: 26 Sep 2018, 13:48
by marci
Tks David for the answer.

Yes I have Node-red and MQTT running on a Linux Ubuntu box...

My issue is the TIME it takes to have a inter-controller communication. When one event happen on ControllerONE (a button is pressed) and this message needs to go to ControllerTWO to execute an action (a relay is activated), it takes up to 10 seconds to react!!

I have a rule on ControllerONE that is triggered by the switch. And an event rule on ControllerTWO that can be triggered by a remote command.

The remote command could be part of a rule on ControllerONE or can be part of Node-red / MQTT node.

The three ways (that I know of) to do this communication are:
1) Http like: http://192.168.1.185/control?cmd=event,switch-go1
2) UDP P2P like: sendTo 31,event,switch-go1
3) through MQTT like: publish NODE1/cmd,event,switchgo1. This is the command published in a rule of ControllerONE , but you can have the same done in Node-red node.

THE PROBLEM IS THE TIME IT TAKES TO EXECUTE THE COMMAND. When you do any of these ways you don't have an immediate reaction! Reaction time can be between 1 to 10 seconds

ControllerTWO is very busy...load around 40%. It manages 8 relays trough an MCP23017 and 10 switches.

There is any other way to do Inter-controller Communication ? Are you having delay issues ? What could be the cause? I use a very recent build

tks
Marcello

Re: use of switches to manage lights in the house

Posted: 26 Sep 2018, 14:28
by papperone
I use a lot communication betweem modules and as well my protocol is MQTT.
I don't have any delays and the only possibility I can think of is the "MQTT MESSAGE DELAY" parameters in the TOOLS/ADVANCED screen which could be way too high.
I set it on 100ms to have a very responsive messages reaction by all modules.

I would check as well the setting on MQTT broker (mine is running on Raspberry so cannot help much).
Use maybe an MQTT messagge monitor (e.g. mqttspy) to check the time betwen a node send the message and the actual receving of that message, I just tested and in my case is close to real-time (delay is in a matter of few milliseconds...)