If you want the relay to be open when the power is off, you should use different contacts. So instead of normally closed use normally open contacts.
-
Invert mysensors relay
-
If i power up the node now when i am not at home the red led is burning.
But when i’m at home and i power it up after a couple of seconds also the green light burns.
this is because it gets a signal from the gateway i guess. -
try to Change the head section of your Code from
#define RELAY_ON 1
#define RELAY_OFF 0to
#define RELAY_ON 0
#define RELAY_OFF 1edit: if there are only Start-up Problems edit
// Make sure relays are off when starting up
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, RELAY_OFF);to
// Make sure relays are off when starting up
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, RELAY_ON); -
@derksuh
How about to change your script.#define RELAY_ON 0 #define RELAY_OFF 1
-
Jup, change the HIGH and LOW in your script and your fine, also make sure that after you set the pin for ouput you change the relay state so it is in it’s OFF state.
Like my projects and help? Consider donating electroneum etnjwAKGPqF6omQWRmpp9u2BPyVDG9VuyRQjNJ1S8yfBdfR9qeUQ46kRy8KS2CNqbpNLRrsgmNW6F2TMzxmZgPrh6KctrkrYbm
-
Tried what was wroted above but that didn’t do the trick.
When starting up the node the relay is not activated, as soon as it connected to the gateway the relay is activated so it has to do something with the gateway. -
curious… maybe @sweebee knows a solution??
-
In setup
request(CHILD_ID_RLAY, V_STATUS);
You are requesting the status from the relay from the gateway, that sets the relay to the status known by the controller.
If the gateway starts, do you see the debug output “Received message…”?
-
I did not get it working the way i would like. I now used a different sketch.
here i had the same problem but i just set the relay_OFF from 0 to 1, and the Relay_ON from 1 to 0
And with this sketch it worked fine.#define MY_NODE_ID 1 // Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include <SPI.h> #include <MySensors.h> #include <DHT.h> #define CHILD_ID_HUM 1 #define CHILD_ID_TEMP 2 #define HUMIDITY_SENSOR_DIGITAL_PIN 6 unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) unsigned long lastRefreshTime = 0; // Use this to implement a non-blocking delay function #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 DHT dht; float lastTemp; float lastHum; boolean metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); void setup() { dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); metric = getConfig().isMetric; for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); } } void presentation() { // Send the Sketch Version Information to the Gateway sendSketchInfo("Badkamer", "1.3"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); 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) present(sensor, S_LIGHT); } } void loop() { boolean needRefresh = (millis() - lastRefreshTime) > SLEEP_TIME; if (needRefresh) { lastRefreshTime = millis(); float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT"); } else if (temperature != lastTemp) { lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } send(msgTemp.set(temperature, 1)); Serial.print("T: "); Serial.println(temperature); } float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum) { lastHum = humidity; send(msgHum.set(humidity, 1)); Serial.print("H: "); Serial.println(humidity); } } } void receive(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 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()); } }
-
This sketch is only reading last known state from eeprom, not requesting it from node. So it will not notice a change of state during a downtime, but that’s no problem I think…