A required update! When I added some new switches in December 2017 I slowly reaslised I needed to move to the MQTT environment of Cayenne. This was in a way a blessing in disguise; the sketch I used at that moment had sometimes difficulties to connect (and restarted often duing the timer loop). It was also a good moment to make some additional changes:
- So the 'biggest' change was to move from the Arduino Library to the Cayenne MQTT environment; in the sketch use channels over virtual 'pins' and rebuilding the dashboard. And here is one of the real good benefits of MQTT; sensor appears automatic in the dashboard. Because I do for switches (=custom widget ‘button’ as actuator) also some displaywrites to reflect present state of a switch it is possible you need to delete the automatic create ones
- Replaced the RST-sensor with online query to the NTP-server
- Refreshed Summer Time (DST) check based upon the NTP data and used in Tardis routine for Sunrise and sunset
- Added DHT22-sensor
- Added Wi-Fi signal and system uptime information on the dashboard
- Added obsolete scheduling routines in "some Rube Goldberg logic" style (whatever that is) to tackle present misbehavior of scheduling and triggers. Hope at some point in time this part is really obsolete and we can relay on Cayenne's Triggers and Scheduling!!!! The dashboard has an actuator to (de-)activate this.
Please do not consider this as completely original work. I work according to the C&P-T&E principles. What do I want, get inspired by others try to implement them in my own projects.
I try to document as best as possible, references, keeps things together and sometime simplify. I know for myself that a few weeks later I might be clueless about something I have done or were I found it and at that moment; some additional info in the sketch can be very helpful at that point. Any suggestions are welcome.
Learnings of this version.
- Invert logic is simply achieved by ! (no need for a routine)
- For sunset/sunrise small trick to see if we are in DST (summertime)
The MQTT environment feels a bit ‘slower’ than the Arduino version but is surely more stable. So the downside can be that the action of the actuator is not directly done/visible. But where is this problem? We need to realise a lot of ‘middleware’ is between the request and action: finger – WiFi – lan – wan – Cayenne server (MQTT broker) – wan – lan – wifi – sensor – action.
Next version might be with an ESP32;)
This is my 2nd project with Cayenne. First published in December 2016. I revised it a bit and also corrected a stupid error in the DST-calculation which only became evident when DST started in 2017. The project itself is based on a static sketch running for several months now where a handful of lights follow sunset to go on; major objective here is that there is no need to adjust time over the months (the farther you are away from the equator, the more you will require this). In December 2016 I converted this to Cayenne because I was missing manual controls (or have to use three different remotes), the sketch does not need to be updated when switches are added because they can be programmed from inside the dashboard and on/off actions can be scheduled and/or triggered!
What's Connected
See the "things" section. Off course you only need the Wemos or the UNO+W5100. There are also a lot of Self-learning power switches and I surely will not promise you they all will work with the Flamingo library. Finding out the proper codes will be cumbersome but I found them too.
Remarks:
- 433MHz Wireless Transmitter will improve if you add an antenna. Still need to solder the included cupper one but about 17 cm will do the trick too.
- How to recognise a self-learning switch? Self-learning switches do not have any dipswitches but when plugged in power you get some time to program them with either the supplied remote or now with Cayenne. In the Netherlands the switches are sold with names like Flamingo F500, some “klik aan klik uit" variants, Elro 8-serie and the cheapest from Action 3 for 10 euro. The Action switches are also easy because they give you more time for programming the switch.
- Older 433 switches will have dip, rotery switches and depending on the brand require different libraries to operate.
For the older 433 switches and a different variant of self-learning switches use the library from Randy Simons (other libraries are available). With the NewRemoteTransmitter you will be able to address the Flamingo SF-501PWD outdoor switch.
Some Functionality Explained:- Flamingo library is created by others who invested their time to understand what kind of 433 sequences the remote controls were sending to activate a switch. These codes are converted again by someone into the flamingo library. My contribution is limited with some simplification to make this library more Cayenne friendly; It used to have a remote-unit key, I converted it to (virtual) single code key so it can respond on the Cayenne’s’ virtual channel V0 to V7. More codes might be available.
- Time library. Why use the time library? In the old project the device was instable this is solved with the timer function which only communicates with the Cayenne server in a 10 seconds interval. In this section the present time (V20) is calculated, DST, sunrise (V21), sunset V22) and “night time” (V25).
- The RTC-module (DS3231) is added for two reasons. • Unaware if the time can be retrieved from Cheyenne • Use the alarm function for DST (second only) Some lines are set to comment, you can use this section to reset your RTC-module and/or to set a new time. Please note that the present time will be about 20 seconds of (differences caused due time lapse between the compile time and actual reset of RTC-time in sketch, you might want to program the RTC-time in a simple sketch.
- Display of the values: How to display the sunset and sunrise time as best as possible? In the absence of the colon make a point (Amerika likely sees a comma).
- Daylight Saving Time (DST) for CET.
- Sunset/Sunrise calculation and display; The Sunset/Sunrise is calculated with “TimeLord tardis” in combination with the GPS location. It also uses the variable “DST_check” to add hours for the DST-offset in summer.
- Offset Slider creates a delay and lights can be switch e.g. 30 minutes after sunset (or 30 minutes before sunrise).
The dashboard has the following items:
- V0 to V7; 8 switches for self learning devices
- V15 and V16; two older elro-switches (dip-switches)
- Time displayed; sunset, sunrise, present time (redundent info) which are used to see if we are in "night time or "day time".
- Offset slider to influence the extended night time (ignore that it is in degrees).
- Offset; The result of this offset slider (redundent)
Basicly this is nothing nothing more than switching lights on and off. When do you want to do this?
- Lights on at sunset
- Lights on at x minutes before sunset
- Lights off at midnight or so
- Lights off at sunrise
- Lights off at x minutes before sunrise
Video of project f.y.i. Using my Android phone only for display here. With my desktop I select the widget, this will result that the status of the widget and the light on the switch will change.
Small Improvements over timeAdded a slider to the device in order to have more flexibility in the twilight zone. Ok, think a bit more explanation might be justified. In the Netherlands the sunset is changing daily with about 3 minutes (or so). But when the sun sets it is not dark yet! So I wanted to introduce an offset to this sunset. The perfect way to do this is to add a slider and adjust the sunset with for example 30 minutes and lights can be switched automatic 30 minutes after sunset. The actual automation is done with a trigger (V24). The offset widget (V19) is in principle obselete but in the past useful to see if values came through truely.
if (time_now >= time_sunset + time_offset || time_now <= time_sunrise - time_offset) { //delay for twilight offset set by slider
Cayenne.virtualWrite(V24, 1);
} else {
Cayenne.virtualWrite(V24, 0);
Another very, very small improvement was achieved when I realized something better with "invert logic". Benefit is mostly a more condensed sketch (because this part is repeated 8 times). Especially the UNO+W5100 combination is lacking memory with this sketch. This:
CAYENNE_IN(V0) // action switch lamp V0
{
if (getValue.asInt() == 1) {
Flamingo_Send(V0, 0); // ON
} else {
Flamingo_Send(V0, 1); // OFF
}
is replayced by:
CAYENNE_IN(V0) // action switch lamp V0
{
Flamingo_Send(V0, getValue.asInt()); // ON or OFF
}
is the MQTT-version this is replaced by:
CAYENNE_IN(0) // action switch lamp 0
{
Flamingo_Send(0, !getValue.asInt()); // ON or OFF
}
Please observe the "!" before getvalue to invert result!
Some remarks
Cayenne/Mydevices is also evolving and solutions (read workarounds) in this sketch maybe integrated in the Cayenne/Mydevices functionality.
Dec '17 Sketches, etc updated to reflect latest MQTT version!
Comments