I also made some changes for the battery sensor. It uses icons now which i think looks much better. The look of the icon depends on the value of the battery.
-
How to Mysensors.
-
@sweebee I built the same PIR sensor as you did with the Arduino mini pro, mini NRF with shield and battery.
Is the above sketch of 21 days ago still the latest version?
I’m very interested in the battery control you implemented.
When I have my DHT available I will probably extend this sensor with that and adjust my sketch. -
@Petjepet This is my latest:
#include <MySensor.h> #include <SPI.h> #include <readVcc.h> // ********** CONFIG ********************************** #define NODE_ID AUTO // ID of node #define CHILD_ID 1 // ID of sensor #define PIR_PIN 3 // Pin connected to the PIR #define MIN_V 2000 // empty voltage (0%) #define MAX_V 3200 // full voltage (100%) // **************************************************** MyMessage msg(CHILD_ID, V_TRIPPED); MySensor node; int oldBatteryPcnt = -1; int sentValue = -1; int forceSend = 0; void setup() { node.begin(NULL, NODE_ID, false); node.sendSketchInfo("PIR Sensor", "1.3"); node.present(CHILD_ID, S_MOTION); pinMode(PIR_PIN, INPUT); } void loop() { // Get PIR sendPir(); // Send batterylevel sendBattery(); // Sleep until something happens with the sensor node.sleep(PIR_PIN-2, CHANGE); } // FUNCTIONS void sendPir() { int value = digitalRead(PIR_PIN); // Get value of PIR if (value != sentValue) { // If status of PIR has changed resend(msg.set(value), 5); // Send PIR status to gateway sentValue = value; } } void sendBattery() // Send battery percentage to GW { forceSend++; int batteryPcnt = min(map(readVcc(), MIN_V, MAX_V, 0, 100), 100); // Get VCC and convert to percentage if (batteryPcnt != oldBatteryPcnt || forceSend >= 20) { // If battery percentage has changed node.sendBatteryLevel(batteryPcnt); // Send battery percentage to gateway oldBatteryPcnt = batteryPcnt; forceSend = 0; } } void resend(MyMessage &msg, int repeats) // Resend messages if not received by GW { int repeat = 0; int repeatDelay = 0; boolean ack = false; while ((ack == false) and (repeat < repeats)) { if (node.send(msg)) { ack = true; } else { ack = false; repeatDelay += 100; } repeat++; delay(repeatDelay); } }
-
@sweebee Thanks!
-
@sweebee Thanks for sharing!.
Just curious, but what’s the use of all those PIRs (you have 10+ of them, right?)
Do you use it to control lights or heating? as a security system? or is it just for fun? -
I would want to use them as a kind of security system.
When adjusted and placed smart it PIRs would function as in a alarm system only detecting actually people in the room. -
@lxz mainly for controlling the lights.
2 in the living room that automatically turn the lights on if the light value is Lower than xx%
1 in the kitchen that automatically turns the lights on if the light value is lower than xx%. And if it’s night only 1 light goes on and goes automatically off. You don’t want them to go off when your eating haha.
I have 3 hallways with pirs that turns the lights on and off on movement. Also depends on the light value. And one extra on the stairs so it goes on before I enter the hall room.
2 in the bathroom for lights. And 1 in the garden that turns the pumps of the water fountain on if it’s after sunrise, warmer than 15 degrees and if there is movement. They go auto off after sunset.
Oh and one on the toilet not to forget
-
i want to use your sketch too for a movement-controlled night-light and switching some devices based by room/time-combination like bathradio in the morning or turning LCD Infodisplays on/off - thanks for sharing @sweebee
i think i could also take your script for soil-measuring of my plants and window/door-contact sensors for heating-control -
@sweebee
What does your device definition look like in Pimatic?
What USB programmer do you use for the Mini? I have a FT232RL and issues on getting ik work properly on Windows 10.
How do you check for your node id settings with the mini? Monitoring through the FT232RL with Ardino IDE doesn’t seem to work. -
@Petjepet like this:
{ "id": "woonkamer-pir1", "xPresentLabel": "Gedetecteerd", "xAbsentLabel": "Wachten", "name": "PIR woonkamer entree", "class": "MySensorsPIR", "nodeid": 1, "sensorid": 1, "autoReset": false, "batterySensor": true },
I use also a FT232RL and it works “fine” on my mac. The only problem i have is that once I have ejected it from my usb port and plug it back in it won’t work anymore until I reboot.
Easiest way to check the node id is boot the node up when attached to the arduino ide and the serialport should output something like sensor started at node id X.
Or look at the pimatic log to see which id sends.
-
@sweebee
Regarding the FT232RL I already noticed the same.I did not see anything sent. I guess the node isn’t working correct:
send: 0-0-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=fail:0 send: 0-0-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=fail:1.5.4 send: 0-0-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0 sensor started, id=0, parent=0, distance=0 send: 0-0-0-0 s=255,c=3,t=11,pt=0,l=10,sg=0,st=fail:PIR Sensor send: 0-0-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:1.3 send: 0-0-0-0 s=1,c=0,t=1,pt=0,l=0,sg=0,st=fail: find parent send: 0-0-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: send: 0-0-0-0 s=1,c=1,t=16,pt=2,l=2,sg=0,st=fail:0 send: 0-0-0-0 s=1,c=1,t=16,pt=2,l=2,sg=0,st=fail:0 send: 0-0-0-0 s=1,c=1,t=16,pt=2,l=2,sg=0,st=fail:0 send: 0-0-0-0 s=1,c=1,t=16,pt=2,l=2,sg=0,st=fail:0 send: 0-0-0-0 s=1,c=1,t=16,pt=2,l=2,sg=0,st=fail:0 send: 0-0-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,st=fail:100 find parent send: 0-0-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
al lot of fails.
I got the sketch on the mini pro but during that also had sync messages in Ardino IDE.
Does your sketch upload generate strange communication messages? -
your node can’t reach the gateway. Also its using nodeid 0. Try to upload the cleareepromconfig in mysensors example sketches. wait a few seconds and re-upload the pir sketch, it should ask for a node id from the gateway. or change
#define NODE_ID AUTO
to#define NODE_ID 1
How close is your gateway to the node?
-
Distance is about 2 meters now. I do not hope it is a radio issue. I checked the contacts to the Arduino to be soldered right.
Pimatic also tells me "betterySensor is not a valid property. I downloaded the MySensors library last Friday.
Try to use Arduino IDE and again the com port busy message. Do I need to restart my PC every time I use the FT232RL? Need an other solution for that…
-
@Petjepet yes battery sensor is not yet included in the current npm version. use the latest from github. I asked dheerej to update the npm today but he still didn’t do it.
Maybe you get the fail because its id is set to 0, same as the gateway.
-
ID is set to auto so I get one from parent.
Did the “cleareepromconfig” and uploaded the sketch having a sync error again (AVRDUDE something).
Now monitoring:find parent send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: sensor started, id=255, parent=255, distance=255 find parent send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: find parent send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: find parent send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: find parent send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: find parent send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: find parent send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: find parent send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: find parent send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: find parent send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
I’m afraid the radio is not working. What do you think?
-
@Petjepet find parent means he is looking for the gateway or a repeater, but he gets no response from the gateway or a repeater.
Does the gateway receive anything (pimatic log)? If not it could be the gateway thats not working.
-
The gateway is working since already have a DST node for test purposes running for a week now.
I notice the led at the mini first flashing flawless and after time more brighter. Is this led indicating send messages?
-
@Petjepet yes the led means he is sending. Do you have another nrf to test?
-
@Petjepet oh yes that are ‘fake’ ones. You need the nrfs with the square chip.