@user2684 Thanks for reporting. I have updated the instructions with the Sonoff details.
Posts made by Efflon
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
-
RE: π¬ Window Sensor with Sensebender (high WAF)
@antonholmstedt a pro mini fits if you cut the corners, check out https://forum.mysensors.org/topic/6612/door-sensor-remix-of-some-mys-community-efforts
-
RE: π¬ NodeManager
@user2684 I have a sonoff and have posted a few examples here https://www.mysensors.org/build/sonoff, nodeManager would maybe save a few lines of code for the end user but you will have quite a lot to code I guess if you add esp8266 support, the sonoff is just a relay with a LED and a button which nodeManager already supports.
-
Door sensor, remix of some MYS community efforts
This project is a remix of a few other MYS project. The base is the excellent Window Sensor with Sensebender (high WAF) where I thought I could get some use of the tiny jModule instead. I ended up ordering from a link to dirtyPCBs in the comments.
This is the start, dirt cheap but still looks ok.
Rip it open, de-solder the glass reed switch and don't bend the pins since that will most likely kill it. Use a dremmel and remove some excess plastic in the top part of the speaker fitting.
Assemble your jModule. I didn't use any bent pins since the space is extremely limited.
As you see, the wiring is just the reed switch to GND and 3. Power and GND to the edge of the jModule (on to VCC of pro mini). Since it's battery powered the pro mini LED is removed (destroyed ) and traces cut. Cut the corners of the pro mini (!) to make it fit.
Last but not least, some code. I gave NodeManager by @user2684 a try and it makes things almost to easy
/* * For v1.3 * Register below your sensors */ nodeManager.setBatteryMin(1.8); nodeManager.setBatteryMax(3.2); nodeManager.setBatteryReportCycles(2); nodeManager.registerSensor(SENSOR_DOOR,3); nodeManager.setSleep(SLEEP,3,HOURS); /* * Register above your sensors */
Every 6 hous the sensor will report battery status. On open or close it will report state then go back to sleep.
The second sensor took 15 minutes to assemble, quite ok imho...
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
@warmaniac You dont need mqtt/mosquitto. Just follow the guide at https://www.domoticz.com/wiki/MySensors for adding a "MySensors Gateway with LAN interface (Ethernet)" then follow the ethernet sketch here https://www.openhardware.io/view/318/Sonoff-relay-using-MySensors-ESP8266-wifi-or-mqtt-gateway
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
@warmaniac the sonoff works just like any sensor except its configured as a gateway since that is what is needed for esp8266+mysensors . Mqtt or ethernet/wifi is just a matter of taste and your setup, skip mqtt if you don't have anything else using it.
-
RE: NodeManager: plugin for a rapid development of battery-powered sensors
@mar.conte if it's sleeping, it will not receive anything until wake-up. If you change the sleep mode to wait,
nodeManager.setSleepMode(WAIT); [or] nodeManager.setSleep(WAIT,1,HOURS);
the sensor will be awake all the time (and drain your battery).
-
RE: NodeManager: plugin for a rapid development of battery-powered sensors
@user2684 said in NodeManager: plugin for a rapid development of battery-powered sensors:
behavior, in the dev branch the default behavior is now the opposite: waking up from an interrupt does not count as a cycle. The drawback though is that if the sensor triggers continuously, it will never report the battery to the controller since unable to complete a full sleep
This is tricky. Myself uses the battery report as a heartbeat on top of checking the battery level, thus I only need the info once or twice a day. Not sending on wake-up is good since it will preserve battery. I guess a combination the right sleeping time and cycle count could end up quite ok. For a front door sensor, 4h sleep and 2 cycle count would report battery level after the night and then maybe one more time, max 3 times per day, which is more than enough. I'll test the dev branch after some sleep
Btw, great work!! and yes, using wait works just fine, no other issues so far.
-
RE: NodeManager: plugin for a rapid development of battery-powered sensors
@user2684 Excellent!
A question, I'm doing a simple door sensornodeManager.setBatteryMin(1.8); nodeManager.setBatteryMax(3.2); nodeManager.setBatteryReportCycles(1); int door = nodeManager.registerSensor(SENSOR_DOOR,3); ((SensorDoor*)nodeManager.get(door))->setDebounce(500); nodeManager.setSleep(SLEEP,1,HOURS);
Now, the node is constantly sending. It seems as if every wake-up triggers a sending, and a wakeup from the debounce sleep, then battery reporting etc.. Removing the debounce helps and lets the node sleep.
AWAKE SEND D=0 I=200 C=1 T=48 S=AWAKE I=0 F=0.00 BATT V=3.16 P=97 SEND D=0 I=201 C=0 T=38 S= I=0 F=3.16 SWITCH I=1 P=3 V=0 SEND D=0 I=1 C=1 T=16 S= N=0 F=0.00 SLEEP 60s SEND D=0 I=200 C=1 T=48 S=SLEEPING I=0 F=0.00 [here i "open" the door] WAKE P=3, M=1 AWAKE SEND D=0 I=200 C=1 T=48 S=AWAKE I=0 F=0.00 BATT V=3.16 P=97 SEND D=0 I=201 C=0 T=38 S= I=0 F=3.16 SWITCH I=1 P=3 V=1 SEND D=0 I=1 C=1 T=16 S= N=1 F=0.00 SLEEP 60s SEND D=0 I=200 C=1 T=48 S=SLEEPING I=0 F=0.00 [just a second wait] WAKE P=3, M=1 AWAKE SEND D=0 I=200 C=1 T=48 S=AWAKE I=0 F=0.00 BATT V=3.16 P=97 SEND D=0 I=201 C=0 T=38 S= I=0 F=3.16 SWITCH I=1 P=3 V=1 SEND D=0 I=1 C=1 T=16 S= N=1 F=0.00 SLEEP 60s [repeated until closing "door"]
Edit:
I changed the sleep to a wait and now the behavior is correct (this line).
// what do to during loop void SensorSwitch::onLoop() { // wait to ensure the the input is not floating if (_debounce > 0) wait(_debounce); // read the value of the pin int value = digitalRead(_pin);
MY I=8 M=1 SEND D=0 I=200 C=0 T=48 S=STARTED I=0 F=0.00 SWITCH I=1 P=3 V=0 SEND D=0 I=1 C=0 T=16 S= N=0 F=0.00 SLEEP 60s SEND D=0 I=200 C=1 T=48 S=SLEEPING I=0 F=0.00 [open] WAKE P=3, M=1 AWAKE SEND D=0 I=200 C=1 T=48 S=AWAKE I=0 F=0.00 BATT V=3.16 P=97 SEND D=0 I=201 C=0 T=38 S= I=0 F=3.16 SWITCH I=1 P=3 V=1 SEND D=0 I=1 C=1 T=16 S= N=1 F=0.00 SLEEP 60s SEND D=0 I=200 C=1 T=48 S=SLEEPING I=0 F=0.00 [close] WAKE P=3, M=1 AWAKE SEND D=0 I=200 C=1 T=48 S=AWAKE I=0 F=0.00 BATT V=3.16 P=97 SEND D=0 I=201 C=0 T=38 S= I=0 F=3.16 SWITCH I=1 P=3 V=0 SEND D=0 I=1 C=1 T=16 S= N=0 F=0.00 SLEEP 60s SEND D=0 I=200 C=1 T=48 S=SLEEPING I=0 F=0.00
-
RE: NodeManager: plugin for a rapid development of battery-powered sensors
I just started playing with this and must say FANTASTIC! This makes things almost too simple.
I found a few small thingsΒ΄(bugs?)
- You refer to the sourforge page for the latest releases (nit pick)
- Baud in the config.h is default set to 9800, shouldn't this be 9600? However, setting it to whatever doesn't help, only 4800 outputs anything, this could be something on my setup as well ...
Again, thanks!
-
RE: π¬ Window Sensor with Sensebender (high WAF)
Thanks for the inspiration! I ordered a bunch and post my progress soon.
-
RE: JULA motion LED hack
@engy I never let the sensor stay for to long since it was so ugly and seemed to drain my batteries fast. What I eventually did was restore it to its original state with a light and light-sensor and powered with a usb charger. Now when motion is detected an event with the light intensity is sent to my HASS server, who then decides if the light should turn on or not....
-
LM35 temp sensor, sensitive to radiation or?
I got a bunch of LM35 sensors (3-pin) from Aliexpress and have some trouble with them reporting to high temperature readings. When connected to my breadboard with 15cm cables I had "normal" readings 20-21C. Now when I'm assembling a wemos D1 mini with a OLED in a tiny box I get 26C even with the sensor 2cm outside and with a heat shield (alu-foil and electrical tape). Anyone knows if this sensor is sensitive to e.g. wifi signals or just IR from the esp8266?
-
RE: π¬ NodeManager
Wow! This seems to make things extremely simple. The documentation is really good but I wish you had a few example sketches to make things even more easy (and help us who can't bother to read all documentation ;D ).
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
@Bryden It's hidden in the code of the sketch "* Hold Sonoff button when attaching FTDI to flash."
-
RE: Housing/Box for ESP8266Wlan Gateway
I have a just tested a few wemos D1 mini pro from the Aliexpress/wemos store. They are top notch imho, you cannot find anything better for 5$ (of ESP8266 based boards). They are very small and come ready for stacking with extra boards. Fast shipping to...
-
RE: Nexa smoke alarm hack
@marceltrapman Haven't had the time to add an ack to the battery request, but the sensor is working just fine. I don't know if it's my home assistant setup or something else causing the battery levels to get lost but I'm sure it's not part of the smoke alarm hack. Since the sensor drain is almost nothing, the battery levels are not moving much.
I cant guarantee the pcb layout is the same on newer versions of this smoke alarm.. -
RE: Nexa smoke alarm hack
@marceltrapman Yes, I'll check if adding a ack request will help..
-
RE: Nexa smoke alarm hack
@marceltrapman It's working just fine except the battery level messages seems to be lost (this happens to all my sensors). Just as a precaution I pushed the test button this morning and got a proper response and a battery level.
-
RE: π¬ Battery Powered Sensors
@GertSanders Thanks for you explanation. I thought vvc on the short end next to rx was going through the voltage regulator just as RAW. Anyhow I have already de-soldered the LED's and are powering through vcc next to A3. Apparently my voltage regulators are bad so I'll cut the lines and give it a try and hope power consumption stays low.
-
RE: π¬ Battery Powered Sensors
If I power my 3.3V miniPro through VCC, do I still need to remove/cut the voltage regulator?
I thought the current moved from vvc-in/raw through the regulator and then to the MCU and VCC .
My battery powered nodes are dying and I suspect I need to change BOD and eventually something more (LED gone ).. -
JULA motion LED hack
I found a cheap (β¬5) battery powered motion sensor LED at jula.se that I couldn't resist to pry open.
Looking at the PCB I found the standard BISS0001 used in most PIR motion sensors.
I de-soldered LED resistor and the resistor connecting the IC with the transistor causing the LED to shine. The bottom orange cable is the sensor output going HIGH when motion is detected. In this sensor trigger time was set to 25s by a 10K resistor at R2, I have replaced it with a short=0 to only have part of a second output (look at the datasheet for more details). The photo resistor is also removed unless you only want night triggering. Pin 9 on the IC, blue circle, is used to enable/disable the sensor. I have left it untouched, for now.Since it's powered by 3xAAA=4,5V I take 3V from the top right VDC regulator (?).
It all fits just fine in the box..ehh
The example motion sketch have been used as base for my code. I have made some small changes. I disable motion detection for 30min after first trigger. I sleep for 6hours before reporting battery level. Interrupt is triggered by RISING.
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Motion Sensor example using HC-SR501 * http://www.mysensors.org/build/motion * */ // Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include <MySensors.h> #include <Vcc.h> const float VccMin = 2.0*0.6; // Minimum expected Vcc level, in Volts. Example for 2xAA Alkaline. const float VccMax = 2.0*1.5; // Maximum expected Vcc level, in Volts. Example for 2xAA Alkaline. const float VccCorrection = 1.0/1.0; // Measured Vcc by multimeter divided by reported Vcc Vcc vcc(VccCorrection); // h m s ms unsigned long SLEEP_TIME = 6UL * 60UL * 60UL * 1000UL; // Sleep time between reports (in milliseconds) unsigned long DISABLE_TIME = 30UL * 60UL * 1000UL; // Time until sensor is re-enabled after triggering (in milliseconds) #define MOTION_SENSOR_PIN 2 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define CHILD_ID 0 // Id of the sensor child // Initialize motion message MyMessage msg(CHILD_ID, V_TRIPPED); int wakeup = 0; void setup() { pinMode(MOTION_SENSOR_PIN, INPUT); // sets the motion sensor digital pin as input } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Motion Sensor", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID, S_MOTION, "Motion tripped", true); } void loop() { // Read digital motion value bool tripped = digitalRead(MOTION_SENSOR_PIN) == HIGH; if (tripped) { send(msg.set(1)); // Send tripped value to gw send(msg.set(0)); // Send tripped value to gw // Ignore any motion for a set time sleep(DISABLE_TIME); } // Send battery level when waking up from long sleep if (wakeup == -1) { uint8_t batteryPcnt = static_cast<uint8_t>(0.5 + vcc.Read_Perc(VccMin, VccMax)); // Send battery level, used as heartbeat of the sensor sendBatteryLevel(batteryPcnt); } // Sleep until interrupt comes in on motion sensor. Send update every two minute. wakeup = sleep(digitalPinToInterrupt(MOTION_SENSOR_PIN), RISING, SLEEP_TIME); }
-
RE: Leaving sleep() with interrupt, prevents going back to sleep() properly
@Yveaux I'm using the latest 2.1.1 . The retriggering is possible to handle in the code and all seems possible to run on batteries so I am happy.
-
RE: Leaving sleep() with interrupt, prevents going back to sleep() properly
@Yveaux I finally did what you said. I powered the sensor by it self and have just GND and input connected. Now I don't get a false trigger after a sleep! Is there anything I could do to prevent this, a capacitor or something?
After a trigger, it seems impossible to enter sleep no matter how long I delay etc. It always takes one sleep() with a immediate wake up before going to sleep. Is there someway to clear the interrupt flag?
-
RE: Leaving sleep() with interrupt, prevents going back to sleep() properly
@Yveaux Introducing a delay() causes the interrupt to to be triggered immediately with a triggered:0 , with a wait() same thing except triggered: 1 . Super strange imho...
-
RE: Leaving sleep() with interrupt, prevents going back to sleep() properly
@Yveaux Great tip but in this case I have tried the PIR with "plain" arduino code and with mysensors. To explain even better, this is the only change I have introduced compared to the online example:
void loop() { // Read digital motion value bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; Serial.print("tripped: "); Serial.println(tripped); //send(msg.set(tripped?"1":"0")); // Send tripped value to gw // Sleep until interrupt comes in on motion sensor. Send update every two minute. sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), RISING, SLEEP_TIME); }
Sleep is triggeered by RISING since change triggers both in up and down of the sensor. The log is like this when no trigger occurs:
4950 TSF:MSG:READ,0-0-2,s=255,c=3,t=27,pt=1,l=1,sg=0:1 4956 MCO:PIM:NODE REG=1 4960 MCO:BGN:STP 4962 MCO:BGN:INIT OK,TSP=1 tripped: 0 4964 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255 4970 MCO:SLP:TPD 4972 MCO:SLP:WUP=1 tripped: 1 4974 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255 4980 MCO:SLP:TPD # Here it actually sleeps 30s 4982 MCO:SLP:WUP=-1 tripped: 0 4984 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255 4990 MCO:SLP:TPD 4993 MCO:SLP:WUP=1 tripped: 1 4995 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255 5001 MCO:SLP:TPD # Here it actually sleeps 30s
So after a long sleep it wakes up, then enters sleep and interrupt is somehow triggered and the pinout reads triggeered. The next long sleep is the same..
If i add a pulldown resistor from 3 to GND and disconnects the sensor pin after a -1 (wakeup) it enters sleep properly. I'm a complete n00b in electronics but to me it seems like some sort of signal bouncing after wakup. Then sensor is powered by vcc... -
RE: Home Assistant does not recognise the switch
@martinhjelmare Can the first/initial send() be done last in the presentation() function or does it have to be in the loop()?
-
Leaving sleep() with interrupt, prevents going back to sleep() properly
I'm trying building a sensor using the standard motion sketch but are having some issues.
- After waking up from sleep without any interrupts triggering, sleep is entered and immediately exited. In the next loop, sleep is entered correctly.
- The wake-up seems to trigger the PIR or at least do something with the interrupt pin after sleep. The sensor is modded to only send a very short output.
In the sketch I have added some debug prints where each loop() starts with a "---->" and then 5 reads of the tripped state with a delay(100) in-between. I have also commented out the send() part for a less verbose log.
In the log bellow the sensor is coming out of a 30s sleep with no interrupts triggering. The sensor seems to trigger after 100ms and then resumes to un-triggered and the node goes to sleep to immediately wake up. Then it goes back to sleep as it should...
My main concern is the instant wake-up after sleep since I have seen it in my fire alarm hack. Is it a MYS bug or something with my mini-pros?
[MYS 2.1.1, Arduino 1.8.1]... Tripped: 0 13207 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255 13213 MCO:SLP:TPD 13217 MCO:SLP:WUP=-1 ---> Tripped: 0 Tripped: 1 Tripped: 1 Tripped: 1 Tripped: 1 ---> Tripped: 1 Tripped: 0 Tripped: 0 Tripped: 0 Tripped: 0 14024 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255 14032 MCO:SLP:TPD 14034 MCO:SLP:WUP=1 ---> Tripped: 0 Tripped: 0 Tripped: 0 Tripped: 0 Tripped: 0 14440 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255 14446 MCO:SLP:TPD ---> Tripped: 0 ...
-
RE: Interrupt and sleep
@JoergP Don't know. I just select "mini pro" from within Arduino IDE.
I'll create a new trouble shooting topic with my problem since this is going out of topic. -
RE: Wemos XI
@korttoma Why use ESP8266? isnt it 328 clone so you could use Mini pro in arduino ?
-
RE: Interrupt and sleep
@JoergP Sorry, what I meant was regarding the versions you were using to get your sensor to work. I've been fighting to get interrupts to work for a day and your suggestion helped.
Now it's just that going out of sleep triggers the PIR, then it goes for sleep and wakes up immediately and then finally goes to sleep ... gahhTripped: 0 13207 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255 13213 MCO:SLP:TPD 13217 MCO:SLP:WUP=-1 interrupt: -1 Tripped: 0 Tripped: 1 Tripped: 1 Tripped: 1 Tripped: 1 interrupt: -1 Tripped: 1 Tripped: 0 Tripped: 0 Tripped: 0 Tripped: 0 14024 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255 14032 MCO:SLP:TPD 14034 MCO:SLP:WUP=1 interrupt: 1 Tripped: 0 Tripped: 0 Tripped: 0 Tripped: 0 Tripped: 0 14440 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255 14446 MCO:SLP:TPD```
-
RE: Interrupt and sleep
@JoergP ans others, I have tried versions 1.6.8 and the board definitions 1.6.11 and interrupt seems to work but in the case of using a PIR the sensor somehow seems to be triggered when going out of sleep due to time...
-
RE: π¬ Motion Sensor
@ben999 Did you get your sensor sorted? I have the same issue with the sensor reporting tripped after going out of sleep, same goes for wait. Putting the exact same logic in a sketch without MYS and I have no issues... going crazy soon
-
RE: Home Assistant does not recognise the switch
@erangaj You don't seem to send anything back from your sensor, I believe that is needed for HASS to add it... Spent a night fighting with HASS and similar issues but in the end I don't know exactly what fixed things though...
-
RE: Looking for detailed description for hacking a sonoff
@mgaman Didn't read the pdf, but thanks for the explanation. Nice trick to make installation easier.
-
Nexa smoke alarm hack
Note, I take no responsibilities for modifications you do to your smoke alarm. Use a back up for safety.
I have a few Nexa KD-101Lx smoke detektors with a built in 433MHz radio that just eats batteries so I had the idea to modify them to talk with a simple MySensors node.
The construction is actually a alarm and a radio on the same PCB. Looking at the PCB and a bit of testing I found the connection between the smoke alarm and the radio part.
When the alarm triggers the pin is pulled high and since there already is a 10k pull-up resistor in place all that is needed is to add a cable to my sensor. The "learn" button is re-used for triggering reset and providing ground.
The original radio is powered by 3xAA so I just cut the cable and re-soldered the cables to use only 2xAA's.
I will use the newbiePCB for hooking things up and everything's seems to fit inside the case just fine.
Here is the code that will run for the next couple of days.
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * DESCRIPTION * * Simple fire alarm example modifying a Nexa KD-101L fire alarm * Connect digitial I/O pin 3 (FIRE_PIN below) with a 10K resistor to GND. * Also connect the FIRE_PIN between the IC and R16 (SMD103=10K). */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 #include <MySensors.h> #include <Vcc.h> const float VccMin = 2.0*0.6; // Minimum expected Vcc level, in Volts. Example for 2xAA Alkaline. const float VccMax = 2.0*1.5; // Maximum expected Vcc level, in Volts. Example for 2xAA Alkaline. const float VccCorrection = 1.0/1.0; // Measured Vcc by multimeter divided by reported Vcc Vcc vcc(VccCorrection); // Pin connected to the alarm #define FIRE_PIN 3 // Id of the sensor child #define CHILD_ID 0 // Sleep time in ms min s ms unsigned long SLEEP_TIME = 120UL * 60UL * 1000UL; MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { // Setup the alarm pinMode(FIRE_PIN, INPUT); } void presentation() { // Send the sketch version information sendSketchInfo("Fire Alarm", "1.0"); // Register sensor present(CHILD_ID, S_SMOKE, "Alarm tripped", true); // Send the current state //send(msg.set("0")); } void loop() { bool tripped = digitalRead(FIRE_PIN) == HIGH; if(tripped) { Serial.println("Fire!"); send(msg.set(1), true); wait(1000); } else { Serial.println("All ok"); send(msg.set(0), true); // Measure battery level uint8_t batteryPcnt = static_cast<uint8_t>(0.5 + vcc.Read_Perc(VccMin, VccMax)); // Send battery level, used as heartbeat of the sensor sendBatteryLevel(batteryPcnt); } // Sleep until fire sleep(digitalPinToInterrupt(FIRE_PIN), HIGH, SLEEP_TIME); }
-
RE: Looking for detailed description for hacking a sonoff
@mgaman Interesting code but I have a hard time understanding how you set ssid + passwd , through mqtt with your hard coded wifi user pass?
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
@Jan-Gatzke Thanks! A Interesting and inspiring code example. Did you think about using the arduinoOTA option instead of the httpUpdater?
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
@Jan-Gatzke Excelletn info, thanks! Yes, please share your code , the state doesn't matter for me at least
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
@Jan-Gatzke What code modifications have you done to get the touch buttons to work or do they work like "normal" buttons? I really like the built-in form factor and was thinking about ordering a few.
-
RE: ESP8266 MQTT gateway + sonoff_MQTT code + vera + HA_Bridge + Alexa, oh my
@stephenmhall ahh, serial gateway. Then just forget all I wrote...
-
RE: ESP8266 MQTT gateway + sonoff_MQTT code + vera + HA_Bridge + Alexa, oh my
@stephenmhall What I mean is by using the ESP8266 wifi sketch with my presentation etc. code (not the top mqtt parts) the sonoff will talk standard "MYS ethernet code" with your MYS controller.
Untested example code:
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik EKblad * Contribution by a-lurker and Anticimex, * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de> * Contribution by Ivo Pullens (ESP8266 support) * * DESCRIPTION * The EthernetGateway sends data received from sensors to the WiFi link. * The gateway also accepts input on ethernet interface, which is then sent out to the radio network. * * VERA CONFIGURATION: * Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin. * E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003 * * LED purposes: * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch, only the LEDs that is defined is used. * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly * - ERR (red) - fast blink on error during transmission error or recieve crc error * * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions. * nRF24L01+ ESP8266 * VCC VCC * CE GPIO4 * CSN/CS GPIO15 * SCK GPIO14 * MISO GPIO12 * MOSI GPIO13 * GND GND * * Not all ESP8266 modules have all pins available on their external interface. * This code has been tested on an ESP-12 module. * The ESP8266 requires a certain pin configuration to download code, and another one to run code: * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch') * - Connect GPIO15 via 10K pulldown resistor to GND * - Connect CH_PD via 10K resistor to VCC * - Connect GPIO2 via 10K resistor to VCC * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch') * * Inclusion mode button: * - Connect GPIO5 via switch to GND ('inclusion switch') * * Hardware SHA204 signing is currently not supported! * * Make sure to fill in your ssid and WiFi password below for ssid & pass. */ // Enable debug prints to serial monitor #define MY_DEBUG // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h #define MY_BAUD_RATE 9600 // Enables and select radio type (if attached) #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_GATEWAY_ESP8266 #define MY_ESP8266_SSID "MySSID" #define MY_ESP8266_PASSWORD "MyVerySecretPassword" // Enable UDP communication //#define MY_USE_UDP // Set the hostname for the WiFi Client. This is the hostname // it will pass to the DHCP server if not static. // #define MY_ESP8266_HOSTNAME "sensor-gateway" // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) //#define MY_IP_ADDRESS 192,168,178,87 // If using static ip you need to define Gateway and Subnet address as well #define MY_IP_GATEWAY_ADDRESS 192,168,178,1 #define MY_IP_SUBNET_ADDRESS 255,255,255,0 // The port to keep open on node server mode #define MY_PORT 5003 // How many clients should be able to connect to this gateway (default 1) #define MY_GATEWAY_MAX_CLIENTS 2 // Controller ip address. Enables client mode (default is "server" mode). // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 // Enable inclusion mode #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway // #define MY_INCLUSION_BUTTON_FEATURE // Set inclusion mode duration (in seconds) #define MY_INCLUSION_MODE_DURATION 60 // Digital pin used for inclusion mode button #define MY_INCLUSION_MODE_BUTTON_PIN 3 // Set blinking period // #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Flash leds on rx/tx/err // Led pins used if blinking feature is enabled above #define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin #define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin #define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED #if defined(MY_USE_UDP) #include <WiFiUdp.h> #endif #include <ESP8266WiFi.h> #include <MySensors.h> #include <Bounce2.h> #define BUTTON_PIN 0 // Sonoff pin number for button #define RELAY_PIN 12 // Sonoff pin number for relay #define LED_PIN 13 // Sonoff pin number for LED #define RELAY_ON 1 #define RELAY_OFF 0 #define LED_ON 0 #define LED_OFF 1 // Id of the sensor child #define CHILD_ID 0 Bounce debouncer = Bounce(); int oldValue = 0; bool state = false; MyMessage msg(CHILD_ID,V_STATUS); void setup() { // Setup the button pinMode(BUTTON_PIN, INPUT_PULLUP); // After setting up the button, setup debouncer debouncer.attach(BUTTON_PIN); debouncer.interval(5); // Make sure relays and LED are off when starting up digitalWrite(RELAY_PIN, RELAY_OFF); digitalWrite(LED_PIN, LED_OFF); // Then set relay pins in output mode pinMode(RELAY_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT); } void presentation() { // Send the sketch version information sendSketchInfo("Sonoff", "1.0"); // Register sensor present(CHILD_ID, S_BINARY); // Send the current state send(msg.set(state?true:false)); // Blink when ready blink(); } void loop() { debouncer.update(); // Get the update value int value = debouncer.read(); if (value != oldValue && value==0) { // Toggle the state state = state?false:true; // Change relay state digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Change LED state digitalWrite(LED_PIN, state?LED_ON:LED_OFF); // Send new state send(msg.set(state)); } oldValue = value; } void receive(const MyMessage &message) { // We only react on status messages from the controller // to this CHILD_ID. if (message.type==V_STATUS && message.sensor==CHILD_ID) { // Change relay state // Only switch if the state is new if (message.getBool() != state) { state = message.getBool(); // Change relay state digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Change LED state digitalWrite(LED_PIN, state?LED_ON:LED_OFF); // Send the current state send(msg.set(state)); } } } void blink() { digitalWrite(LED_PIN, digitalRead(LED_PIN)?LED_ON:LED_OFF); wait(200); digitalWrite(LED_PIN, digitalRead(LED_PIN)?LED_ON:LED_OFF); wait(200); digitalWrite(LED_PIN, digitalRead(LED_PIN)?LED_ON:LED_OFF); wait(200); digitalWrite(LED_PIN, digitalRead(LED_PIN)?LED_ON:LED_OFF); }
-
RE: Battery powered temp sensor, minimize drain?
@mfalkvidd Thanks, I have read the link and followed the instructions regarding the LED. I will re-build my sensor to use a dedicated pin for power instead.
But wait! Since it's only when measuring I have a voltage division with 10000, the normal case would be 3.3V/(10000+~10000)=0.15mA and thus 500days? Well, a bit of code instead of changing batteries is better. -
Battery powered temp sensor, minimize drain?
I have build a simple battery powered sensor using a simple voltage divider as described here. The resistor (10k) is connected to Vcc just as the battery and I measure voltage between thermistor(10k) and ground. Will this constant connection drain the battery or should I have one pin powering the circuit just when I want to wake up the sensor and measure?
-
RE: ESP8266 MQTT gateway + sonoff_MQTT code + vera + HA_Bridge + Alexa, oh my
@stephenmhall aha! But vera runs MYS? Then using my code with the ESP8266 wifi sketch should work without all in-between stuff? (just guessing)..
-
RE: ESP8266 MQTT gateway + sonoff_MQTT code + vera + HA_Bridge + Alexa, oh my
@stephenmhall Cool! With my Sonoff example there is not a must to use HASS or mqtt. A MYS gateway or a standard mqtt broker would work fine. Anyway, as long as things work, life is good . What I don't understand is where the mqtt broker is running?
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
This is not listed as a gateway but under sensors & actuators but maybe a "s/and/relay using" would be a fix of the headline. I selected the mqtt gateway example just because I have a few other NodeMCU's working as just MYS sensors with no radio but it's trivial to just re-use code for any of the other gateways, as you all know. I choose the mqtt addition just for fun and know there are other mqtt examples but nothing working out of the box with my HASS + MYS + mqtt setup. Regarding the gateway naming, at least I don't know any other way of using MYS and ESP8266 than using the gateway sketches with a disabled radio. What should they be called, just node? At the same time, adding a radio to the Sonoff and it's a gateway...
-
RE: Looking for detailed description for hacking a sonoff
Here is a working example of using Sonoff with MySensors and the mqtt gateway.
No need to replace any flash etc... -
RE: Sonoff + MySensors mqtt gateway + Home-Assistant
@hek Yes, just have to figure out how
-
Sonoff + MySensors mqtt gateway + Home-Assistant
Edit: This information is now maintained here and now includes both ethernet and mqtt gateway examples.
I just got my hands on a Sonoff wifi switch and have adapted the MySensors mqtt gateway example to work work with the Sonoff relay and Home Assistant
I have not used it with 220V yet but its tested as you can see.
At start up the LED will blink twice once the presentation is done and then start in the off state.
The button will toggle on off and send the state back to the gateway.
The gateway can also send state to the Sonoff.
If you have multiple Sonoff's they can all use the same mqtt topic as long as they don't have the same child id./** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * The ESP8266 MQTT gateway sends radio network (or locally attached sensors) data to your MQTT broker. * The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network * * LED purposes: * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly * - ERR (red) - fast blink on error during transmission error or recieve crc error * * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions. * nRF24L01+ ESP8266 * VCC VCC * CE GPIO4 * CSN/CS GPIO15 * SCK GPIO14 * MISO GPIO12 * MOSI GPIO13 * * Not all ESP8266 modules have all pins available on their external interface. * This code has been tested on an ESP-12 module. * The ESP8266 requires a certain pin configuration to download code, and another one to run code: * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch') * - Connect GPIO15 via 10K pulldown resistor to GND * - Connect CH_PD via 10K resistor to VCC * - Connect GPIO2 via 10K resistor to VCC * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch') * * Inclusion mode button: * - Connect GPIO5 via switch to GND ('inclusion switch') * * Hardware SHA204 signing is currently not supported! * * Make sure to fill in your ssid and WiFi password below for ssid & pass. */ /** * Sonoff specific details (IM15116002) * * The sonoff header left to right, relay above, LED below. * [1] vcc 3v3 * 2 rx * 3 tx * 4 gnd * 5 * * In arduinoIDE 1.6.* choose Generic ESP8226 module. * Hold Sonoff button when attaching FTDI to flash. */ // Enable debug prints to serial monitor #define MY_DEBUG // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h #define MY_BAUD_RATE 9600 // No radio in Sonoff // Enables and select radio type (if attached) //#define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_GATEWAY_MQTT_CLIENT #define MY_GATEWAY_ESP8266 // Set this node's subscribe and publish topic prefix #define MY_MQTT_PUBLISH_TOPIC_PREFIX "sonoff-out" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "sonoff-in" // Set MQTT client id #define MY_MQTT_CLIENT_ID "mysensors-sonoff-1" // Enable these if your MQTT broker requires usenrame/password //#define MY_MQTT_USER "username" //#define MY_MQTT_PASSWORD "password" // Set WIFI SSID and password #define MY_ESP8266_SSID "SSiD" #define MY_ESP8266_PASSWORD "password" // Set the hostname for the WiFi Client. This is the hostname // it will pass to the DHCP server if not static. #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway-sonoff-1" // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) //#define MY_IP_ADDRESS 192,168,178,87 // If using static ip you need to define Gateway and Subnet address as well #define MY_IP_GATEWAY_ADDRESS 192,168,0,1 #define MY_IP_SUBNET_ADDRESS 255,255,255,0 // MQTT broker ip address. #define MY_CONTROLLER_IP_ADDRESS 192, 168, 0, 100 // The MQTT broker port to to open #define MY_PORT 1883 // Not tested for Sonoff /* // Enable inclusion mode #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway #define MY_INCLUSION_BUTTON_FEATURE // Set inclusion mode duration (in seconds) #define MY_INCLUSION_MODE_DURATION 60 // Digital pin used for inclusion mode button #define MY_INCLUSION_MODE_BUTTON_PIN 3 // Set blinking period #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Flash leds on rx/tx/err #define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin #define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin #define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED */ #include <ESP8266WiFi.h> #include <MySensors.h> #include <Bounce2.h> #define BUTTON_PIN 0 // Sonoff pin number for button #define RELAY_PIN 12 // Sonoff pin number for relay #define LED_PIN 13 // Sonoff pin number for LED #define RELAY_ON 1 #define RELAY_OFF 0 #define LED_ON 0 #define LED_OFF 1 // Id of the sensor child // Set unique id for each sonoff if sub/pub on same mqtt topic #define CHILD_ID 0 Bounce debouncer = Bounce(); int oldValue = 0; bool state = false; MyMessage msg(CHILD_ID,V_STATUS); void setup() { // Setup the button pinMode(BUTTON_PIN, INPUT_PULLUP); // After setting up the button, setup debouncer debouncer.attach(BUTTON_PIN); debouncer.interval(5); // Make sure relays and LED are off when starting up digitalWrite(RELAY_PIN, RELAY_OFF); digitalWrite(LED_PIN, LED_OFF); // Then set relay pins in output mode pinMode(RELAY_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT); } void presentation() { // Send the sketch version information sendSketchInfo("Sonoff", "1.0"); // Register sensor present(CHILD_ID, S_BINARY); // Send the current state send(msg.set(state?true:false)); // Blink when ready blink(); } void loop() { debouncer.update(); // Get the update value int value = debouncer.read(); if (value != oldValue && value==0) { // Toggle the state state = state?false:true; // Change relay state digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Change LED state digitalWrite(LED_PIN, state?LED_ON:LED_OFF); // Send new state send(msg.set(state)); } oldValue = value; } void receive(const MyMessage &message) { // We only react on status messages from the controller // to this CHILD_ID. if (message.type==V_STATUS && message.sensor==CHILD_ID) { // Change relay state // Only switch if the state is new if (message.getBool() != state) { state = message.getBool(); // Change relay state digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Change LED state digitalWrite(LED_PIN, state?LED_ON:LED_OFF); // Send the current state send(msg.set(state)); } } } void blink() { digitalWrite(LED_PIN, digitalRead(LED_PIN)?LED_ON:LED_OFF); wait(200); digitalWrite(LED_PIN, digitalRead(LED_PIN)?LED_ON:LED_OFF); wait(200); digitalWrite(LED_PIN, digitalRead(LED_PIN)?LED_ON:LED_OFF); wait(200); digitalWrite(LED_PIN, digitalRead(LED_PIN)?LED_ON:LED_OFF); }
The HASS config is not much. Using the persistence file will make HASS restore the desired state if the Sonoff loses power etc.
mysensors: gateways: - device: mqtt persistence_file: '/home/homeassistant/.homeassistant/sonoff.json' topic_in_prefix: 'sonoff-out' topic_out_prefix: 'sonoff-in' debug: false optimistic: false persistence: true retain: true version: 2.0
-
RE: π¬ Relay
@Boots33 Ok, you explanation is what was my only explanation to the "missing" code. When experimenting with this using the mqtt gateway sketch and home-assistant as controller, the ACK is just an ACK and not a "real" message with payload thus just toggling the state bool and getting things out of sync..
-
RE: π¬ Relay
@korttoma
Thanks for the explanation! Just as I suspected with missing relay code. -
RE: π¬ Relay
I'm trying to wrap my head around the button example and don't understand what the loop() really does. To me it only alters the "state" but how does it affect the relay?
Is the button physically connected to the relay or should the controller send the new state back and let the receive() function handle the actual relay switching?
Also, after presentation, shouldn't there be a send() to the controller? -
RE: π¬ Easy/Newbie PCB for MySensors
@mfalkvidd I ordered January 2 and can't remember what version was stated. I'm quite sure I picked Itead because it had a higher version numer (and a slightly higher price), honestly don't remember. All I know is that I didn't read this thread but rather just browsed through the page and clicked order. Afterwards I realized it wasn't clear if it was the 5V or 3.3V version but the order said 5x5cm. I also missed to choose color but "grΓΆnt Γ€r skΓΆnt".
Guess what confused me most was the statement "It may say another rev. at the orderpage but this is not EasyPCB rev but the rev for manufacturer." causing me to be trigger happy -
RE: π¬ Easy/Newbie PCB for MySensors
Gah! I ordered through the https://www.openhardware.io/order/4/PCB10X link from Itead but got the rev8 boards. Thought the "I always update the gerber files for sale" meant it was safe to order...
-
RE: Presentation of 3rd sensor for a node fails....
@robosensor
I have tried the bool in the present() function but it doesn't help setting it to true... -
RE: Presentation of 3rd sensor for a node fails....
I was just about to post a similar conclusion after a hard night trying to figure out why one of my three presentations didn't work (was it my code, HASS, the mqtt-gateway Mys2.1.0 etc..).
Introducing a short gw.wait(X) between each presentation did indeed help. In my case it has been quite random if the second or third presentation fails to register. 20ms was to short but 100ms seems to work
Is there anywhere this could be saved for later, e.g. in the TempHumidity sketch? -
RE: Nodemcu 0.9 + MQTT gateway + TEMP + Motion Sensor
Just browsing through your code since I have a similar setup with a mqtt gateway with a few sensors and had the same problem. The thing is that a gateway shouldn't sleep thus I believe the sleep() function is not working (without looking at the source code). I replaced sleep() with wait() and have it running on usb power.
-
RE: MQTT - NRF24 gateway communication issues
From my short experience, I suspect there is something with the radio as long as you see "proper" messages in your openhab logs (if not, try hard coding the node id in the sketch)..
-
Wemos XI
I just got started building my own sensors and stumbled upon the Wemos XI, https://www.wemos.cc/product/wemos-xi.html . For USD1.50 and no leds or voltage regulator they seems to be quite useful for a battery powered sensor. Anyone tried them?
-
RE: π¬ Air Humidity Sensor - DHT
Ok! I just have to verify it on Atmega first. I'll be back..
-
RE: π¬ Air Humidity Sensor - DHT
Just a note, tried following this for adding a DHT11 to the ESP8266 MQTT gateway. The MySensors example lib does not work with esp8266 (temperatures around 17000+). However the adafruit DHT library 1.3.0 works just fine.Any reason that couldn't be used here?