Some hour later I have a "half baked" code ready.
What it does:
- Heater On/Off relay works
- Temp UP relay works
- Temp Down relay works
What does not work:
- I can't figure out how to read the LED voltage on the control panel and send the status heater on or off back to vera.
Some more info on this:
- The control panel is powered by 12V. I will use the same supply to power the Arduino so I should have shared ground and therefore - I think - I should be able to read the voltage of the power LED pin on the control panel directly, correct?
The idea is to read the voltage (the control uses a pulse to step down the main voltage to power the LED I believe as a reed relay will flip flop if connected directly to the LED) at the LED pin on the panel and, depending on the reading (>2v = on, <2v = off) send vera the on/off status.
This will allow correct representation of the status on vera's side in case someone uses the push button on the panel to control the heater instead of vera and should avoid unknown toggle states.
Below is my code. I have commented the voltage reading out of the loop. if it is enabled the board will not respond anymore.
Quite dirt programming I'm afraid
Any help with this is highly appreciated !!
Thanks !
// Paloma Tankless Water Heater Script
// Direct interface to control panel push buttons with reed relays as well as status check of panel power LED
#include <MySensor.h>
#include <SPI.h>
#include <Bounce2.h>
#define ID 1 // Set Sensor ID
#define PWR_RLY 3 // Arduino Digital I/O pin number for the Power Button
#define UP_RLY 4 // Arduino Digital I/O pin number for the Temp Up Button
#define DWN_RLY 5 // Arduino Digital I/O pin number for the Temp Down Button
#define PWR_LED A0 // Arduino Analogue pin number for the Power LED
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
MySensor gw;
MyMessage msg(ID, V_HEATER_SW);
int saveheatLvl = 0; // save heat level data
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("Water Heater", "1.0");
// Register all sensors to gw (they will be created as child devices)
gw.present(ID, S_HEATER);
// Then set pins
digitalWrite(PWR_RLY,RELAY_OFF);
pinMode(PWR_RLY, OUTPUT);
digitalWrite(UP_RLY,RELAY_OFF);
pinMode(UP_RLY, OUTPUT);
digitalWrite(DWN_RLY,RELAY_OFF);
pinMode(DWN_RLY, OUTPUT);
}
void loop ()
{
// Always process incoming messages whenever possible
gw.process();
// voltage (); // if included will create a loop? and relays are not responding anymore
}
void voltage(){
// Read LED voltage
int sensorValue = analogRead(PWR_LED);
float voltage = sensorValue * (5.0 / 1023.0);
delay (1);
if (voltage == 5) {
gw.send(msg.set("HeatOn"),true); // check LED voltage and set Heat on if 5V detected
}else{
gw.send(msg.set("Off"),true); // check LED voltage and set Off if <5V detected
}
}
void incomingMessage(const MyMessage &message) {
// Check for Heater Switch Message
if (message.type==V_HEATER_SW) {
// Switch Heater On
if (strncmp (message.data,"HeatOn",6) == 0){
Serial.println("Switching Heater ON");
digitalWrite(PWR_RLY,RELAY_ON);
delay(500);
digitalWrite(PWR_RLY,RELAY_OFF);
gw.send(msg.set("HeatOn"),true);
}
// Switch Heater Off
if (strncmp (message.data,"Off",3) == 0){
Serial.println("Switching Heater OFF");
digitalWrite(PWR_RLY,RELAY_ON);
delay(500);
digitalWrite(PWR_RLY,RELAY_OFF);
gw.send(msg.set("Off"),true);
}
}
if (message.type==V_HEATER) {
// Check for Temperature Up/Down Message
int heatLvl = atoi(message.data);
// Check if new Temperature is higher than previous set point
if ( heatLvl > saveheatLvl) {
Serial.println("Increase Temperature");
digitalWrite(UP_RLY,RELAY_ON);
delay(500);
digitalWrite(UP_RLY,RELAY_OFF);
saveheatLvl = heatLvl;
gw.send(msg.set(saveheatLvl),true);
}
// Check if new Temperature is lower than previous set point
if ( heatLvl < saveheatLvl) {
Serial.println("Reduce Temperature");
digitalWrite(DWN_RLY,RELAY_ON);
delay(500);
digitalWrite(DWN_RLY,RELAY_OFF);
saveheatLvl = heatLvl;
gw.send(msg.set(saveheatLvl),true);
}
}
}