Page 1 of 2
Mysensors - Relay Switch
Posted: Monday 16 March 2015 23:20
by filipq
Hello
I have connected my sensors gateway via usb, and it seems to be working fine for a temp/humidy sensor. Unfortunately it doesn't work for a Relay Actuator. I can see under domoticz log that Relay is detected (see attachment), but It doesn't appear under devices list. Can someone help please?
Re: Mysensors - Ralay Switch
Posted: Tuesday 17 March 2015 9:03
by gizmocuz
The log displays that there is a node plugged in, and its reporting the sketch name/version.
However, it does not receive anything (as i can see in the log)
I think this 'relay' (switch) node, is not sending the 'current' switch state to the serial controller ?
Please modify your code a little bit
Do you load/save the state (as in the RelayActuator example) ?
(strongly advised)
Then after sending the sketch info, load the current state,
gw.loadState
- set this state to the real output (digitalWrite or similar call)
- send this state to the serial controller
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msg(CHILD_ID,V_TRIPPED);
gw.send(msg.set(value==HIGH ? 1 : 0));
When you receive a command from the serial controller (to switch a relay), store this state
gw.saveState(message.sensor, message.getBool());
This has multiple advantages:
- when there is a power failure, the relays will automatically be set to the last state
- and domoticz always has the current state
Re: Mysensors - Ralay Switch
Posted: Tuesday 17 March 2015 10:28
by Pino
Maybe this could be the case for my request too.
http://www.domoticz.com/forum/tracker.php?p=2&t=447
I'll try tonight or tomorrow.
EDIT:
tried, this works. In the setup part, after the presentation, send the state back, and domoticz will show the actuator.
Re: Mysensors - Ralay Switch
Posted: Tuesday 17 March 2015 20:01
by gizmocuz
as long as you also implement the load/save state then your fine
Re: Mysensors - Ralay Switch
Posted: Wednesday 18 March 2015 0:18
by filipq
Thanks for that.
Can you send/show your sketch Pino? I'm getting some errors on mine when compiling. Not sure what I'm doing wrong.
Mysensors - Relay Switch
Posted: Wednesday 18 March 2015 17:51
by thegritche
Same as filipq I have some errors in my relay sketch
I don't really understand the gizmocuz's response
Pino, if you have some example it's more easy for me (us ?)
Re: Mysensors - Ralay Switch
Posted: Thursday 19 March 2015 10:09
by floris74
thegritche wrote:Hello
Same as filipq I have some errors in my relay sketch
I don't really understand the gizmocuz's response
Pino, if you have some example it's more easy for me (us ?)
Thanks
+1! thanks! ,, Floris
Mysensors - Relay Switch
Posted: Saturday 28 March 2015 2:01
by filipq
I have managed to get it working. Could you check on yours and post your reply?
Mysensors - Relay Switch
Posted: Sunday 29 March 2015 10:09
by floris74
It didnt work with me.. I still can t see the relays in domoticz. I can see it in MYScontroller. weird...
Re: Mysensors - Relay Switch
Posted: Sunday 29 March 2015 15:11
by Hendrik
try to trigger the relay one time, so domoticz see state changing
Re: Mysensors - Relay Switch
Posted: Sunday 29 March 2015 16:41
by floris74
eehhhh, how can i trigger the relay? when i power on the arduino, the relay switches on, and that is not notifided. stange.
edit;
i did "Clearing EEPROM" and after uploading the sketch, i can see the switch, as a security-sensor. but i cant controll it with domoticz.... any help?
edit;
when i restart the adruino, it doesn't sent each time the switch-state, while the relay is switching on, as progammed in the sketch...

Re: Mysensors - Relay Switch
Posted: Monday 30 March 2015 9:35
by Pino
Code: Select all
// Example sketch showing how to control physical relays.
// This example will remember relay state even after power failure.
#include <MySensor.h>
#include <SPI.h>
#define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 1 // Total number of attached relays
#define RELAY_ON 0 // GPIO value to write to turn on attached relay
#define RELAY_OFF 1 // GPIO value to write to turn off attached relay
MySensor gw;
MyMessage msg(1,V_LIGHT);
void setup()
{
// Initialize library and add callback for incoming messages
gw.begin(incomingMessage, AUTO, true);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Relay", "1.0");
// Fetch relay status
for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
// Register all sensors to gw (they will be created as child devices)
gw.present(sensor, S_LIGHT);
// Then set relay pins in output mode
pinMode(pin, OUTPUT);
// Set relay to last known state (using eeprom storage)
boolean savedState = gw.loadState(sensor);
digitalWrite(pin, savedState?RELAY_ON:RELAY_OFF);
gw.send(msg.set(savedState? 1 : 0));
}
}
void loop()
{
// Alway process incoming messages whenever possible
gw.process();
}
void incomingMessage(const MyMessage &message) {
if (message.type==V_LIGHT) {
boolean relayState = message.getBool();
digitalWrite(message.sensor-1+RELAY_1, relayState?RELAY_ON:RELAY_OFF);
gw.saveState(message.sensor, relayState);
gw.send(msg.set(relayState? 1 : 0));
Mysensors - Relay Switch
Posted: Monday 30 March 2015 17:21
by floris74
Thanks Pino, hope it Will work....
#define RELAY_ON 0 // GPIO value to write to turn on attached relay
#define RELAY_OFF 1 // GPIO value to write to turn off attached relay
Might That be my problem? I have a ethernet gateway. Mysensors is not connected by GPIO. I dont have a Pi at all.
edit; i can see the switch as a light, but i still can't controll the relay....
edit again.... created a serial gateway instead of a ethernetgateway... Voilá!!! It worked!!!! Only problem is that my ethernet-gateway is central located, and my server is on the 2th floor. any idea why it's not working with the ethernetgateway?
Re: Mysensors - Relay Switch
Posted: Monday 06 April 2015 11:54
by gizmocuz
I just build my first mysensors ethernet gateway
It is working
i had a W5100 ethernet shield (for uno), and a arduino nano.
http://i.ebayimg.com/00/s/NjAwWDYwMA==/ ... 880000500F
i connected the shield with the arduino via the ISCP connector, and also wired pin 10 (nothing more is needed to get the ethernet part working)
connected the NRF24L01 Radio module.
Loaded the MySensors ethernet sketch, modified:
- ip address, nothing more
But, you also need to modify the below files (and revert the changes when you have uploaded the sketch)
- libraries/MySensors/MyConfig.h -> remark the #define DEBUG
- libraries/MySensors/Utility/RF24_config.h -> unmark/remove the slashes in front of #define SOFTSPI
Uploaded the sketch, and in domoticz added the MySensors with Lan interface hardware type, ip address, port = 5003
working perfectly
Not sure if i will use this big shield, there is also a small one
Ps. there is a new beta that should work better with the V_LIGHT/S_LIGHT examples
/Rob
Re: Mysensors - Relay Switch
Posted: Monday 06 April 2015 21:39
by floris74
Hi,
thanks a lot! It's getting pretty stable now with my usb-gateway. Maybe later i'll start the adventure again with the ethernet. I did all the modifications, except:
-libraries/MySensors/MyConfig.h -> remark the #define DEBUG
so probably that was my problem.
thanks a lot for the new beta. i have a working 2-relay sensor node now. and a motion-relay sensor node.
Floris
Re: Mysensors - Relay Switch
Posted: Monday 04 May 2015 13:35
by Striffster
@gizmocuz Are you able to turn relay on and off? I've tried to make the EthernetGW work but It seems that I only get oneway communciation, sensors logs to Domoticz but I can't send anything to the sensors, I have a LED attached to a sensor with the Relay software on it. It works using serialgateway and the ethernetGW works when testing with the MYSController

. Is there any setting in Domoticz to turn on/off twoway communication when using ethernet?
Re: Mysensors - Relay Switch
Posted: Tuesday 05 May 2015 0:17
by floris74
Damn!!! after upgrading my relays arent working anymore! GizMoGuz, any help??
Re: Mysensors - Relay Switch
Posted: Thursday 07 May 2015 20:56
by hahi
I recently updated and saw the same issue with alerts not fireing. What I did was upgrade again to Domoticz V2.2416. After upgrading to the lattest version, go into settings and email alerts. Save the email settings and send a test message. I was able to get an alert after doing these.
Re: Mysensors - Relay Switch
Posted: Thursday 07 May 2015 21:30
by floris74
Ehhhh... Does That make mysensors relays work again???
Re: Mysensors - Relay Switch
Posted: Friday 08 May 2015 1:50
by hahi
Just notifcations. My relays work most of the time.