mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-21 08:16:53 +00:00
Merge pull request #391 from MartinHjelmare/update-mysensors
Add example sketches
This commit is contained in:
commit
995d120e89
@ -2,7 +2,7 @@
|
|||||||
layout: page
|
layout: page
|
||||||
title: "MySensors Binary Sensor"
|
title: "MySensors Binary Sensor"
|
||||||
description: "Instructions how to integrate MySensors binary sensors into Home Assistant."
|
description: "Instructions how to integrate MySensors binary sensors into Home Assistant."
|
||||||
date: 2016-02-28 01:20 +0100
|
date: 2016-04-13 14:20 +0100
|
||||||
sidebar: true
|
sidebar: true
|
||||||
comments: false
|
comments: false
|
||||||
sharing: true
|
sharing: true
|
||||||
@ -36,5 +36,53 @@ S_MOISTURE | V_TRIPPED
|
|||||||
|
|
||||||
For more information, visit the [serial api] of MySensors.
|
For more information, visit the [serial api] of MySensors.
|
||||||
|
|
||||||
|
### {% linkable_title Example sketch %}
|
||||||
|
|
||||||
|
```c++
|
||||||
|
/**
|
||||||
|
* Documentation: http://www.mysensors.org
|
||||||
|
* Support Forum: http://forum.mysensors.org
|
||||||
|
*
|
||||||
|
* http://www.mysensors.org/build/binary
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <MySensor.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Bounce2.h>
|
||||||
|
|
||||||
|
#define SN "BinarySensor"
|
||||||
|
#define SV "1.0"
|
||||||
|
#define CHILD_ID 1
|
||||||
|
#define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch.
|
||||||
|
|
||||||
|
MySensor gw;
|
||||||
|
Bounce debouncer = Bounce();
|
||||||
|
MyMessage msg(CHILD_ID, V_TRIPPED);
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
gw.begin();
|
||||||
|
gw.sendSketchInfo(SN, SV);
|
||||||
|
// Setup the button.
|
||||||
|
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||||
|
// After setting up the button, setup debouncer.
|
||||||
|
debouncer.attach(BUTTON_PIN);
|
||||||
|
debouncer.interval(5);
|
||||||
|
gw.present(CHILD_ID, S_DOOR);
|
||||||
|
gw.send(msg.set(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
if (debouncer.update()) {
|
||||||
|
// Get the update value.
|
||||||
|
int value = debouncer.read();
|
||||||
|
// Send in the new value.
|
||||||
|
gw.send(msg.set(value == LOW ? 1 : 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
[main component]: /components/mysensors/
|
[main component]: /components/mysensors/
|
||||||
[serial api]: https://www.mysensors.org/download/serial_api_15
|
[serial api]: https://www.mysensors.org/download/serial_api_15
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
layout: page
|
layout: page
|
||||||
title: "MySensors Light"
|
title: "MySensors Light"
|
||||||
description: "Instructions how to integrate MySensors lights into Home Assistant."
|
description: "Instructions how to integrate MySensors lights into Home Assistant."
|
||||||
date: 2016-03-02 18:20 +0100
|
date: 2016-04-13 14:20 +0100
|
||||||
sidebar: true
|
sidebar: true
|
||||||
comments: false
|
comments: false
|
||||||
sharing: true
|
sharing: true
|
||||||
@ -33,5 +33,80 @@ V_TYPES with a star (\*) denotes required V_TYPES. Use either V_LIGHT or V_STATU
|
|||||||
|
|
||||||
For more information, visit the [serial api] of MySensors.
|
For more information, visit the [serial api] of MySensors.
|
||||||
|
|
||||||
|
### {% linkable_title Example sketch %}
|
||||||
|
|
||||||
|
```c++
|
||||||
|
/*
|
||||||
|
* Documentation: http://www.mysensors.org
|
||||||
|
* Support Forum: http://forum.mysensors.org
|
||||||
|
*
|
||||||
|
* http://www.mysensors.org/build/dimmer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <MySensor.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#define SN "DimmableRGBLED"
|
||||||
|
#define SV "1.0"
|
||||||
|
#define CHILD_ID 1
|
||||||
|
#define LED_PIN 5
|
||||||
|
|
||||||
|
MySensor gw;
|
||||||
|
|
||||||
|
char rgb[7] = "ffffff"; // RGB value.
|
||||||
|
int currentLevel = 0; // Current dimmer level.
|
||||||
|
MyMessage dimmerMsg(CHILD_ID, V_PERCENTAGE);
|
||||||
|
MyMessage lightMsg(CHILD_ID, V_STATUS);
|
||||||
|
MyMessage rgbMsg(CHILD_ID, V_RGB);
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
gw.begin(incomingMessage);
|
||||||
|
gw.sendSketchInfo(SN, SV);
|
||||||
|
gw.present(CHILD_ID, S_RGB_LIGHT);
|
||||||
|
// Send initial values.
|
||||||
|
gw.send(lightMsg.set(currentLevel > 0 ? 1 : 0));
|
||||||
|
gw.send(dimmerMsg.set(currentLevel));
|
||||||
|
gw.send(rgbMsg.set(rgb));
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
gw.process();
|
||||||
|
}
|
||||||
|
|
||||||
|
void incomingMessage(const MyMessage &message) {
|
||||||
|
if (message.type == V_RGB) {
|
||||||
|
// Retrieve the RGB value from the incoming message.
|
||||||
|
// RGB LED not implemented, just a dummy print.
|
||||||
|
String hexstring = message.getString();
|
||||||
|
hexstring.toCharArray(rgb, sizeof(rgb));
|
||||||
|
Serial.print("Changing color to ");
|
||||||
|
Serial.println(rgb);
|
||||||
|
gw.send(rgbMsg.set(rgb));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.type == V_STATUS || message.type == V_PERCENTAGE) {
|
||||||
|
// Retrieve the light status or dimmer level from the incoming message.
|
||||||
|
int requestedLevel = atoi(message.data);
|
||||||
|
|
||||||
|
// Adjust incoming level if this is a V_LIGHT update [0 == off, 1 == on].
|
||||||
|
requestedLevel *= (message.type == V_STATUS ? 100 : 1);
|
||||||
|
|
||||||
|
// Clip incoming level to valid range of 0 to 100
|
||||||
|
requestedLevel = requestedLevel > 100 ? 100 : requestedLevel;
|
||||||
|
requestedLevel = requestedLevel < 0 ? 0 : requestedLevel;
|
||||||
|
|
||||||
|
// Change level value of LED pin.
|
||||||
|
analogWrite(LED_PIN, (int)(requestedLevel / 100. * 255));
|
||||||
|
currentLevel = requestedLevel;
|
||||||
|
|
||||||
|
// Update the gateway with the current V_STATUS and V_PERCENTAGE.
|
||||||
|
gw.send(lightMsg.set(currentLevel > 0 ? 1 : 0));
|
||||||
|
gw.send(dimmerMsg.set(currentLevel));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
[main component]: /components/mysensors/
|
[main component]: /components/mysensors/
|
||||||
[serial api]: https://www.mysensors.org/download/serial_api_15
|
[serial api]: https://www.mysensors.org/download/serial_api_15
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
layout: page
|
layout: page
|
||||||
title: "MySensors"
|
title: "MySensors"
|
||||||
description: "Instructions how to integrate MySensors sensors into Home Assistant."
|
description: "Instructions how to integrate MySensors sensors into Home Assistant."
|
||||||
date: 2016-02-18 20:13 +0100
|
date: 2016-04-13 14:20 +0100
|
||||||
sidebar: true
|
sidebar: true
|
||||||
comments: false
|
comments: false
|
||||||
sharing: true
|
sharing: true
|
||||||
@ -31,7 +31,7 @@ mysensors:
|
|||||||
debug: true
|
debug: true
|
||||||
persistence: true
|
persistence: true
|
||||||
version: '1.5'
|
version: '1.5'
|
||||||
optimistic: 'true'
|
optimistic: false
|
||||||
```
|
```
|
||||||
|
|
||||||
Configuration variables:
|
Configuration variables:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
layout: page
|
layout: page
|
||||||
title: "MySensors Sensor"
|
title: "MySensors Sensor"
|
||||||
description: "Instructions how to integrate MySensors sensors into Home Assistant."
|
description: "Instructions how to integrate MySensors sensors into Home Assistant."
|
||||||
date: 2016-02-28 01:20 +0100
|
date: 2016-04-13 14:20 +0100
|
||||||
sidebar: true
|
sidebar: true
|
||||||
comments: false
|
comments: false
|
||||||
sharing: true
|
sharing: true
|
||||||
@ -58,5 +58,53 @@ By using V_UNIT_PREFIX, it's possible to set a custom unit for any sensor. The s
|
|||||||
|
|
||||||
For more information, visit the [serial api] of MySensors.
|
For more information, visit the [serial api] of MySensors.
|
||||||
|
|
||||||
|
### {% linkable_title Example sketch %}
|
||||||
|
|
||||||
|
```c++
|
||||||
|
/**
|
||||||
|
* Documentation: http://www.mysensors.org
|
||||||
|
* Support Forum: http://forum.mysensors.org
|
||||||
|
*
|
||||||
|
* http://www.mysensors.org/build/light
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <MySensor.h>
|
||||||
|
#include <BH1750.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#define SN "LightLuxSensor"
|
||||||
|
#define SV "1.0"
|
||||||
|
#define CHILD_ID 1
|
||||||
|
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
|
||||||
|
|
||||||
|
BH1750 lightSensor;
|
||||||
|
MySensor gw;
|
||||||
|
MyMessage msg(CHILD_ID, V_LEVEL);
|
||||||
|
MyMessage msgPrefix(CHILD_ID, V_UNIT_PREFIX); // Custom unit message.
|
||||||
|
uint16_t lastlux = 0;
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
gw.begin();
|
||||||
|
gw.sendSketchInfo(SN, SV);
|
||||||
|
gw.present(CHILD_ID, S_LIGHT_LEVEL);
|
||||||
|
lightSensor.begin();
|
||||||
|
gw.send(msg.set(lastlux));
|
||||||
|
gw.send(msgPrefix.set("lux")); // Set custom unit.
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
uint16_t lux = lightSensor.readLightLevel(); // Get Lux value
|
||||||
|
if (lux != lastlux) {
|
||||||
|
gw.send(msg.set(lux));
|
||||||
|
lastlux = lux;
|
||||||
|
}
|
||||||
|
|
||||||
|
gw.sleep(SLEEP_TIME);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
[main component]: /components/mysensors/
|
[main component]: /components/mysensors/
|
||||||
[serial api]: https://www.mysensors.org/download/serial_api_15
|
[serial api]: https://www.mysensors.org/download/serial_api_15
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
layout: page
|
layout: page
|
||||||
title: "MySensors Switch"
|
title: "MySensors Switch"
|
||||||
description: "Instructions how to integrate MySensors switches into Home Assistant."
|
description: "Instructions how to integrate MySensors switches into Home Assistant."
|
||||||
date: 2016-03-02 18:20 +0100
|
date: 2016-04-13 14:20 +0100
|
||||||
sidebar: true
|
sidebar: true
|
||||||
comments: false
|
comments: false
|
||||||
sharing: true
|
sharing: true
|
||||||
@ -40,5 +40,50 @@ S_MOISTURE | V_ARMED
|
|||||||
|
|
||||||
For more information, visit the [serial api] of MySensors.
|
For more information, visit the [serial api] of MySensors.
|
||||||
|
|
||||||
|
### {% linkable_title Example sketch %}
|
||||||
|
|
||||||
|
```c++
|
||||||
|
/*
|
||||||
|
* Documentation: http://www.mysensors.org
|
||||||
|
* Support Forum: http://forum.mysensors.org
|
||||||
|
*
|
||||||
|
* http://www.mysensors.org/build/relay
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <MySensor.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#define SN "Relay"
|
||||||
|
#define SV "1.0"
|
||||||
|
#define CHILD_ID 1
|
||||||
|
#define RELAY_PIN 3
|
||||||
|
|
||||||
|
MySensor gw;
|
||||||
|
MyMessage msgRelay(CHILD_ID, V_STATUS);
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
gw.begin(incomingMessage);
|
||||||
|
gw.sendSketchInfo(SN, SV);
|
||||||
|
// Initialize the digital pin as an output.
|
||||||
|
pinMode(RELAY_PIN, OUTPUT);
|
||||||
|
gw.present(CHILD_ID, S_BINARY);
|
||||||
|
gw.send(msgRelay.set(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
gw.process();
|
||||||
|
}
|
||||||
|
|
||||||
|
void incomingMessage(const MyMessage &message)
|
||||||
|
{
|
||||||
|
if (message.type == V_STATUS) {
|
||||||
|
// Change relay state.
|
||||||
|
digitalWrite(RELAY_PIN, message.getBool() ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
[main component]: /components/mysensors/
|
[main component]: /components/mysensors/
|
||||||
[serial api]: https://www.mysensors.org/download/serial_api_15
|
[serial api]: https://www.mysensors.org/download/serial_api_15
|
||||||
|
Loading…
x
Reference in New Issue
Block a user