From 36698f122777df739e0b8409ce963b5e80ecc50e Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Tue, 7 Feb 2017 21:20:26 +0100 Subject: [PATCH] Add mysensors device tracker (#1986) * Add mysensors device tracker * Add release info --- .../binary_sensor.mysensors.markdown | 2 +- source/_components/climate.mysensors.markdown | 2 +- .../device_tracker.mysensors.markdown | 105 ++++++++++++++++++ source/_components/light.mysensors.markdown | 2 + source/_components/sensor.mysensors.markdown | 2 +- source/_components/switch.mysensors.markdown | 2 +- 6 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 source/_components/device_tracker.mysensors.markdown diff --git a/source/_components/binary_sensor.mysensors.markdown b/source/_components/binary_sensor.mysensors.markdown index 2d1c74226cf..488bb713f6d 100644 --- a/source/_components/binary_sensor.mysensors.markdown +++ b/source/_components/binary_sensor.mysensors.markdown @@ -86,4 +86,4 @@ void loop() ``` [main component]: /components/mysensors/ -[serial api]: https://www.mysensors.org/download/serial_api_15 +[serial api]: http://www.mysensors.org/download diff --git a/source/_components/climate.mysensors.markdown b/source/_components/climate.mysensors.markdown index 0a3150cc5bc..2ee210d76f4 100644 --- a/source/_components/climate.mysensors.markdown +++ b/source/_components/climate.mysensors.markdown @@ -116,4 +116,4 @@ void incomingMessage(const MyMessage &message) { ``` [main component]: /components/mysensors/ -[serial api]: https://www.mysensors.org/download/serial_api_15 +[serial api]: http://www.mysensors.org/download diff --git a/source/_components/device_tracker.mysensors.markdown b/source/_components/device_tracker.mysensors.markdown new file mode 100644 index 00000000000..be28b220e80 --- /dev/null +++ b/source/_components/device_tracker.mysensors.markdown @@ -0,0 +1,105 @@ +--- +layout: page +title: "MySensors Device Tracker" +description: "Instructions how to use MySensors to track devices in Home Assistant." +date: 2017-02-06 15:00 +0100 +sidebar: true +comments: false +sharing: true +footer: true +logo: mysensors.png +ha_category: Presence Detection +featured: false +ha_release: "0.38" +ha_iot_class: "Local Push" +--- + +Integrates MySensors device trackers into Home Assistant. See the [main component] for configuration instructions. + +The following sensor types are supported: + +##### MySensors version 2.0 and higher + +S_TYPE | V_TYPE +-------------------|--------------------------------------- +S_GPS | V_POSITION + +For more information, visit the [serial api] of MySensors. + +### {% linkable_title MySensors 2.x example sketch %} + +```cpp +/** + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * http://www.mysensors.org/build/gps + */ + +// Enable debug prints to serial monitor +#define MY_DEBUG +// Enable and select radio type attached +#define MY_RADIO_NRF24 +//#define MY_RADIO_RFM69 + +#include + +#define SN "GPS Sensor" +#define SV "1.0" + +// GPS position send interval (in millisectonds) +#define GPS_SEND_INTERVAL 30000 +// The child id used for the gps sensor +#define CHILD_ID_GPS 1 + +MyMessage msg(CHILD_ID_GPS, V_POSITION); + +// Last time GPS position was sent to controller +unsigned long lastGPSSent = -31000; + +// Some buffers +char latBuf[11]; +char lngBuf[11]; +char altBuf[6]; +char payload[30]; + +// Dummy values. Implementation of real GPS device is not done. +float gpsLocationLat = 40.741895; +float gpsLocationLng = -73.989308; +float gpsAltitudeMeters = 12.0; + +void setup() { + +} + +void presentation() { + sendSketchInfo(SN, SV); + present(CHILD_ID_GPS, S_GPS); +} + +void loop() +{ + unsigned long currentTime = millis(); + + // Evaluate if it is time to send a new position + bool timeToSend = currentTime - lastGPSSent > GPS_SEND_INTERVAL; + + if (timeToSend) { + // Send current gps location + // Build position and altitude string to send + dtostrf(gpsLocationLat, 1, 6, latBuf); + dtostrf(gpsLocationLng, 1, 6, lngBuf); + dtostrf(gpsAltitudeMeters, 1, 0, altBuf); + sprintf(payload, "%s,%s,%s", latBuf, lngBuf, altBuf); + + Serial.print(F("Position: ")); + Serial.println(payload); + + send(msg.set(payload)); + lastGPSSent = currentTime; + } +} +``` + +[main component]: /components/mysensors/ +[serial api]: http://www.mysensors.org/download diff --git a/source/_components/light.mysensors.markdown b/source/_components/light.mysensors.markdown index 8abeb4a3cfd..4bf9a9d28a8 100644 --- a/source/_components/light.mysensors.markdown +++ b/source/_components/light.mysensors.markdown @@ -111,6 +111,7 @@ void incomingMessage(const MyMessage &message) { } } ``` + ### {% linkable_title MySensors 2.x example sketch %} ```cpp @@ -244,5 +245,6 @@ void send_status_message() } } ``` + [main component]: /components/mysensors/ [serial api]: http://www.mysensors.org/download diff --git a/source/_components/sensor.mysensors.markdown b/source/_components/sensor.mysensors.markdown index 755ab8f74fe..6324f833db7 100644 --- a/source/_components/sensor.mysensors.markdown +++ b/source/_components/sensor.mysensors.markdown @@ -181,4 +181,4 @@ void receive(const MyMessage &message) { ``` [main component]: /components/mysensors/ -[serial api]: https://www.mysensors.org/download/serial_api_15 +[serial api]: http://www.mysensors.org/download diff --git a/source/_components/switch.mysensors.markdown b/source/_components/switch.mysensors.markdown index ead64bdcbe3..974843207e7 100644 --- a/source/_components/switch.mysensors.markdown +++ b/source/_components/switch.mysensors.markdown @@ -203,4 +203,4 @@ void incomingMessage(const MyMessage &message) { ``` [main component]: /components/mysensors/ -[serial api]: https://www.mysensors.org/download/serial_api_15 +[serial api]: http://www.mysensors.org/download