csharpWorm / Alarm

Code for the Arduino MEGA to take wired inputs and send MQTT auto discovery messages based on their status
MIT License
5 stars 0 forks source link

Add support for Sensors #4

Open csharpWorm opened 3 years ago

csharpWorm commented 3 years ago

Add support for Sensors.

Thoughts are to: 1) Create a generic class that can be extended 2) over time add different sensor support unless I can figure out a more generic way to read/publish sensor data From the little research I've done on this it seems each sensor is unique in how it should be read and how the value should be converted into a human readable.

wdwithmp commented 3 years ago

you are a legend mate

csharpWorm commented 3 years ago

@wdwithmp Get code from this branch https://github.com/csharpWorm/Alarm/tree/Setup_Moisture_Sensor to test the moisture sensor.

In alarm.ino around line 73 you should see the initialization of the moisture sensor. image The 560 and 260 values are the "airValue", and "waterValue" respectively. These will need to be set to the values your sensor gives you when exposed to air and when submerged in water up to the line. image

If you want to create a new arduino file for getting these test values you can use the below and just compile to the Mega, void setup() { Serial.begin(9600); // open serial port, set the baud rate as 9600 bps } void loop() { int val; val = analogRead(0); //connect sensor to Analog 0 Serial.println(val); //print the value to serial port delay(100); }

csharpWorm commented 3 years ago

The sensor should automatically be added to Home Assistant via MQTT discovery and the value should be pased to the state topic and the value extracted using the value_template feature. Let me know if you run into any issues.

wdwithmp commented 3 years ago

Hi Mate, awesome works like a charm. Will try to figure out the template part by reading and looking at what others have done, if I am not able to figure it out I will ask for help, this is way more than I expected

Thanks again for taking the time to help

csharpWorm commented 3 years ago

Glad it's working for you. I didn't have a sensor to test with so wasn't quite sure if it would do what it needed to.

artibea commented 11 months ago

Hello.

Great work. I'm in a process of implementing your codes in my old alarm. One question. Is there a way to hook up a temperature sensors with your code?

Thanks