Mysensors - Relay Switch

Moderator: leecollings

floris74
Posts: 75
Joined: Sunday 30 November 2014 8:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hoorn, Netherlands
Contact:

Re: Mysensors - Relay Switch

Post by floris74 »

I guess that i had one of those days..... a domoticz update together with a broken wire at the gateway site.... Its looking for a needle in a haystack..... but it's solved now!
floris74
Posts: 75
Joined: Sunday 30 November 2014 8:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hoorn, Netherlands
Contact:

Re: Mysensors - Relay Switch

Post by floris74 »

hi,

i have a problem with 2 relays;
if i switch no 1, number 1 switch and i see it in domoticz, switch 2 is still of
if i switch no 2, number 2 switch and i see it in domoticz, but also number 1 is switched...
after a while my arduino gets confused and i have to reboot the arduino. can anybody help me?
here is my sketch;

// 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 2 // 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("RelayBureau", "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));
}
}
floris74
Posts: 75
Joined: Sunday 30 November 2014 8:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hoorn, Netherlands
Contact:

Re: Mysensors - Relay Switch

Post by floris74 »

I used the standard relay sketch now, which is just working out of the box now!
treb0r
Posts: 10
Joined: Friday 19 June 2015 13:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Mysensors - Relay Switch

Post by treb0r »

Hi
I Have Domoticz on RPi B+ with serial Gateway. As a node arduino Pro Mini with 4-Relay Module. A using following sketch and in domoticz I can see only one swith presented as:"security-sensor" and it working ok (ON and OFF immediatellty)
How, and what shall I change to have available and control all 4 switches?
When there is #define CHILD_ID 1 : I can control 1st switch
When there is #define CHILD_ID 2 : I can control 2nd switch etc
Regards
treb0r


// 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 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 4 // 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
#define CHILD_ID 1 // Id of the sensor child

bool state;
bool value;

MySensor gw;

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, V_LIGHT);
// Then set relay pins in output mode
pinMode(pin, OUTPUT);
// Set relay to last known state (using eeprom storage)
digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
// 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));

}
}


void loop()
{
// Alway process incoming messages whenever possible
gw.process();
}

void incomingMessage(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_LIGHT) {
// Change relay state
digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
// Store state in eeprom
gw.saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}
sundberg84
Posts: 52
Joined: Sunday 17 May 2015 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Sweden
Contact:

Re: Mysensors - Relay Switch

Post by sundberg84 »

Same problem for me :( (Ethernet GW, unchanged relay code from MyS)
All sensors work fine!

Relay is registered fine, but trying to change state gives me nothing.
I can change state on the relay sending commands over the ethernet so the relay works fine.

It seems like there is no command left from Domoticz to MySensors GW for some reason.

Br
Controller: Domoticz (Raspberry PI)
Gateways: MySensors (Ethernet W5100), RFLink
mich007
Posts: 2
Joined: Monday 29 February 2016 23:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Mysensors - Relay Switch

Post by mich007 »

Hello guys,

i uploaded the code and I can see on the command prompt that domoticz is receiving the sketchinfo ( relay) and the version (1.0) ..
but i'm having 18 childs.

How can I have only 1 child (the state of the relay) ?

Thank you,

MN
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest