Consolidate mysensors pages (#22070)

This commit is contained in:
Martin Hjelmare 2022-03-18 21:31:07 +01:00 committed by GitHub
parent 10db733c77
commit 824bbef602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 1062 additions and 1431 deletions

View File

@ -1,82 +0,0 @@
---
title: "MySensors Binary Sensor"
description: "Instructions on how to integrate MySensors binary sensors into Home Assistant."
ha_category:
- DIY
- Binary Sensor
ha_release: 0.14
ha_iot_class: Local Push
ha_domain: mysensors
---
Integrates MySensors binary sensors into Home Assistant. See the [main integration](/integrations/mysensors/) for configuration instructions.
The following sensor types are supported:
## MySensors version 1.4 and higher
| S_TYPE | V_TYPE |
| -------- | --------- |
| S_DOOR | V_TRIPPED |
| S_MOTION | V_TRIPPED |
| S_SMOKE | V_TRIPPED |
## MySensors version 1.5 and higher
| S_TYPE | V_TYPE |
| ------------ | --------- |
| S_SPRINKLER | V_TRIPPED |
| S_WATER_LEAK | V_TRIPPED |
| S_SOUND | V_TRIPPED |
| S_VIBRATION | V_TRIPPED |
| S_MOISTURE | V_TRIPPED |
For more information, visit the [serial API](https://www.mysensors.org/download) of MySensors.
## Example sketch
```cpp
/**
* Documentation: https://www.mysensors.org
* Support Forum: https://forum.mysensors.org
*
* https://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));
}
}
```

View File

@ -1,345 +0,0 @@
---
title: "MySensors HVAC"
description: "Instructions on how to integrate MySensors climate into Home Assistant."
ha_category:
- DIY
- Climate
ha_release: 0.29
ha_iot_class: Local Push
ha_domain: mysensors
---
Integrates MySensors HVAC into Home Assistant. See the [main integration](/integrations/mysensors/) for configuration instructions.
The following actuator types are supported:
## MySensors version 1.5 and higher
| S_TYPE | V_TYPE |
| ------ | ------------------------------------------------------------------------------------ |
| S_HVAC | V_HVAC_FLOW_STATE*, V_HVAC_SETPOINT_HEAT, V_HVAC_SETPOINT_COOL, V_HVAC_SPEED, V_TEMP |
V_HVAC_FLOW_STATE is mapped to the state of the Climate integration in Home Assistant as follows:
| Home Assistant State | MySensors State |
| -------------------- | --------------- |
| HVAC_MODE_COOL | CoolOn |
| HVAC_MODE_HEAT | HeatOn |
| HVAC_MODE_AUTO | AutoChangeOver |
| HVAC_MODE_OFF | Off |
Currently humidity, away_mode, aux_heat, swing_mode is not supported. This will be included in later versions as feasible.
Set the target temperature using V_HVAC_SETPOINT_HEAT in Heat mode, and V_HVAC_SETPOINT_COOL in Cool Mode. In case of any Auto Change Over mode you can use V_HVAC_SETPOINT_HEAT as well as V_HVAC_SETPOINT_COOL to set the both the low bound and the high bound temperature of the device.
You can use V_HVAC_SPEED to control the Speed setting of the Fan in the HVAC.
You can use V_TEMP to send the current temperature from the node to Home Assistant.
For more information, visit the [serial API](https://www.mysensors.org/download) of MySensors.
## Example sketch for MySensors 2.x
{% raw %}
```cpp
/**
* 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 - Toni A - https://github.com/ToniA/arduino-heatpumpir
* Version 2.1 - Author unknown - example script from the Home Assistant website : https://www.home-assistant.io/integrations/climate.mysensors
* Version 2.2 - Eric Van Bocxlaer - based on the example script from the Home Assistant website : https://www.home-assistant.io/integrations/climate.mysensors
* - https://community.home-assistant.io/t/mysensors-hvac-not-showing-up/22540
* Version 2.3 - Eric Van Bocxlaer - correction states send back to home assistant, is expecting text values and not numeric values
*
* DESCRIPTION
* Heatpump controller
*/
// Enable debug prints to serial monitor
//#define MY_DEBUG
// Enable specific RFM69 debug prints to serial monitor
//#define MY_DEBUG_VERBOSE_RFM69
#define MY_NODE_ID 3 // set the node ID manually because a MQTT gateway will not assign automatically a node Id - this must be set before the mysensors.h call
// Enable and select radio type attached. Replace the defines if you use other radio type hardware.
#define MY_RADIO_RFM69
#define MY_RFM69_FREQUENCY RFM69_868MHZ // Set your frequency here
#define MY_IS_RFM69HW // Omit if your RFM is not "H"
#define MY_RFM69_NEW_DRIVER // soft spi for rfm69 radio works only with new driver
//enable radio communication encryption
// more information can be found on https://forum.mysensors.org/topic/10382/security-signing-messages-and-encryption-of-messages-a-guide-or-more-a-summary-of-my-tests?_=1588348189475
//#define MY_ENCRYPTION_SIMPLE_PASSWD "your16bitpassword"
//enable simple signing
//#define MY_SIGNING_SIMPLE_PASSWD "your32bitpassword"
//#define MY_SIGNING_SIMPLE_PASSWD "your16bitpassword"
//enable simple signing and encryption
//#define MY_SECURITY_SIMPLE_PASSWORD "your16bitpassword"
//enable simple signing and encryption
#define MY_SECURITY_SIMPLE_PASSWORD "your32bitpassword"
//enable soft signing
//#define MY_SIGNING_SOFT
//#define MY_SIGNING_REQUEST_SIGNATURES
//#define MY_SIGNING_SOFT_RANDOMSEED_PIN A0
// following hex codes are dummy hex codes, replace by your hexcodes (see the link above how to generate)
//#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = 0,.serial = {0x99,0x88,0x77,0x66,0x55,0x44,0x33,0x22,0x11}},{.nodeId = 1,.serial = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99}}}
#include <MySensors.h> // sketch tested with version 2.3.2, see http://librarymanager/all#MySensors
#define SENSOR_NAME "Heatpump Sensor"
#define SENSOR_VERSION "2.3"
#define CHILD_ID_HVAC 0 // Each radio node can report data for up to 254 different child sensors. You are free to choose the child id yourself.
// You should avoid using child-id 255 because it is used for things like sending in battery level and other (protocol internal) node specific information.
#define IR_PIN 3 // Arduino pin tied to the IR led using Arduino PWM
// Uncomment your heatpump model
//#include <FujitsuHeatpumpIR.h>
//#include <PanasonicCKPHeatpumpIR.h>
//#include <PanasonicHeatpumpIR.h>
//#include <CarrierHeatpumpIR.h>
//#include <MideaHeatpumpIR.h>
//#include <MitsubishiHeatpumpIR.h>
//#include <SamsungHeatpumpIR.h> // sketch tested with version 1.0.15, see http://librarymanager#HeatpumpIR by Toni Arte
//#include <SharpHeatpumpIR.h>
//#include <DaikinHeatpumpIR.h>
//Some global variables to hold the numeric states sent to the airco unit
int POWER_STATE;
int TEMP_STATE;
int FAN_STATE;
int MODE_STATE;
int VDIR_STATE;
int HDIR_STATE;
//Some global variables to hold the text states sent to the home assistant controller
String FAN_STATE_TXT; // possible values ("Min", "Normal", "Max", "Auto")
String MODE_STATE_TXT; // possible values ("Off", "HeatOn", "CoolOn", or "AutoChangeOver")
IRSenderPWM irSender(IR_PIN);
//Change to your own Heatpump
//HeatpumpIR *heatpumpIR = new SamsungAQV12MSANHeatpumpIR();
/*
new PanasonicDKEHeatpumpIR()
new PanasonicJKEHeatpumpIR()
new PanasonicNKEHeatpumpIR()
new CarrierHeatpumpIR()
new MideaHeatpumpIR()
new FujitsuHeatpumpIR()
new MitsubishiFDHeatpumpIR()
new MitsubishiFEHeatpumpIR()
new SamsungAQVHeatpumpIR()
new SamsungFJMHeatpumpIR()
// new SamsungHeatpumpIR() is a protected generic method, cannot be created directly
new SharpHeatpumpIR()
new DaikinHeatpumpIR()
*/
MyMessage msgHVACSetPointC(CHILD_ID_HVAC, V_HVAC_SETPOINT_COOL);
MyMessage msgHVACSpeed(CHILD_ID_HVAC, V_HVAC_SPEED);
MyMessage msgHVACFlowState(CHILD_ID_HVAC, V_HVAC_FLOW_STATE);
bool initialValueSent = false;
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo(SENSOR_NAME, SENSOR_VERSION);
// Register all sensors to gw (they will be created as child devices) by their ID and S_TYPE
present(CHILD_ID_HVAC, S_HVAC, "Thermostat");
}
void setup() {
}
void loop() {
// put your main code here, to run repeatedly:
if (!initialValueSent) {
FAN_STATE_TXT = "Auto"; // default fan start state
TEMP_STATE = 20; // default start temperature
MODE_STATE_TXT = "Off"; // default mode state
send(msgHVACSetPointC.set(TEMP_STATE));
send(msgHVACSpeed.set(FAN_STATE_TXT.c_str()));
send(msgHVACFlowState.set(MODE_STATE_TXT.c_str()));
initialValueSent = true;
}
}
void receive(const MyMessage &message) {
if (message.isAck()) {
Serial.println("This is an ack from gateway");
return;
}
Serial.print("Incoming message for: ");
Serial.print(message.sensor);
String recvData = message.data;
recvData.trim();
Serial.print(", New status: ");
Serial.println(recvData);
switch (message.type) {
case V_HVAC_SPEED:
Serial.println("V_HVAC_SPEED");
if(recvData.equalsIgnoreCase("auto")) FAN_STATE = 0;
else if(recvData.equalsIgnoreCase("min")) FAN_STATE = 1;
else if(recvData.equalsIgnoreCase("normal")) FAN_STATE = 2;
else if(recvData.equalsIgnoreCase("max")) FAN_STATE = 3;
FAN_STATE_TXT = recvData;
break;
case V_HVAC_SETPOINT_COOL:
Serial.println("V_HVAC_SETPOINT_COOL");
TEMP_STATE = message.getFloat();
Serial.println(TEMP_STATE);
break;
case V_HVAC_FLOW_STATE:
Serial.println("V_HVAC_FLOW_STATE");
if (recvData.equalsIgnoreCase("coolon")) {
POWER_STATE = 1;
MODE_STATE = MODE_COOL;
}
else if (recvData.equalsIgnoreCase("heaton")) {
POWER_STATE = 1;
MODE_STATE = MODE_HEAT;
}
else if (recvData.equalsIgnoreCase("autochangeover")) {
POWER_STATE = 1;
MODE_STATE = MODE_AUTO;
}
else if (recvData.equalsIgnoreCase("off")){
POWER_STATE = 0;
}
MODE_STATE_TXT = recvData;
break;
}
sendHeatpumpCommand();
sendNewStateToGateway();
}
void sendNewStateToGateway() {
Serial.println("Status update send to HA:");
Serial.println("*************************");
Serial.println("Mode = " + MODE_STATE_TXT + "(" + (String)MODE_STATE + ")");
Serial.println("Fan = " + FAN_STATE_TXT + "(" + (String)FAN_STATE + ")");
Serial.println("Temp = " + (String)TEMP_STATE);
send(msgHVACFlowState.set(MODE_STATE_TXT.c_str()));
send(msgHVACSpeed.set(FAN_STATE_TXT.c_str()));
send(msgHVACSetPointC.set(TEMP_STATE));
}
void sendHeatpumpCommand() {
Serial.println("Heatpump commands send to airco:");
Serial.println("********************************");
Serial.println("Power = " + (String)POWER_STATE);
Serial.println("Mode = " + (String)MODE_STATE);
Serial.println("Fan = " + (String)FAN_STATE);
Serial.println("Temp = " + (String)TEMP_STATE);
heatpumpIR->send(irSender, POWER_STATE, MODE_STATE, FAN_STATE, TEMP_STATE, VDIR_AUTO, HDIR_AUTO);
}
```
{% endraw %}
## Example sketch for MySensors 1.x
```cpp
/*
* Documentation: https://www.mysensors.org
* Support Forum: https://forum.mysensors.org
*/
#include <MySensor.h>
/*
* Include all the other Necessary code here.
* The example code is limited to message exchange for mysensors
* with the controller (ha).
*/
#define CHILD_ID_HVAC 0 // childId
MyMessage msgHVACSetPointC(CHILD_ID_HVAC, V_HVAC_SETPOINT_COOL);
MyMessage msgHVACSpeed(CHILD_ID_HVAC, V_HVAC_SPEED);
MyMessage msgHVACFlowState(CHILD_ID_HVAC, V_HVAC_FLOW_STATE);
/*
* Include all the other Necessary code here.
* The example code is limited to message exchange for mysensors
* with the controller (ha).
*/
void setup()
{
// Startup and initialize MySensors library.
// Set callback for incoming messages.
gw.begin(incomingMessage);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("HVAC", "0.1");
gw.present(CHILD_ID_HVAC, S_HVAC, "Thermostat");
gw.send(msgHVACFlowState.set("Off"));
gw.send(msgHVACSetPointC.set(target_temp));
gw.send(msgHVACSpeed.set("Max"));
}
void loop() {
// Process incoming messages (like config from server)
gw.process();
}
void incomingMessage(const MyMessage &message) {
String recvData = message.data;
recvData.trim();
switch (message.type) {
case V_HVAC_SPEED:
if(recvData.equalsIgnoreCase("auto")) fan_speed = 0;
else if(recvData.equalsIgnoreCase("min")) fan_speed = 1;
else if(recvData.equalsIgnoreCase("normal")) fan_speed = 2;
else if(recvData.equalsIgnoreCase("max")) fan_speed = 3;
processHVAC();
break;
case V_HVAC_SETPOINT_COOL:
target_temp = message.getFloat();
processHVAC();
break;
case V_HVAC_FLOW_STATE:
if(recvData.equalsIgnoreCase("coolon") && (!Present_Power_On )){
togglePower();
}
else if(recvData.equalsIgnoreCase("off") && Present_Power_On ){
togglePower();
}
break;
}
}
```

View File

@ -1,157 +0,0 @@
---
title: "MySensors Cover"
description: "Instructions on how to integrate MySensors covers into Home Assistant."
ha_category:
- DIY
- Cover
ha_release: "0.30"
ha_iot_class: Local Push
ha_domain: mysensors
---
Integrates MySensors covers into Home Assistant. See the [main integration](/integrations/mysensors/) for configuration instructions.
The following actuator types are supported:
## MySensors version 1.4
| S_TYPE | V_TYPE |
| ------- | ------------------------------------------- |
| S_COVER | V_UP, V_DOWN, V_STOP, [V_DIMMER or V_LIGHT] |
## MySensors version 1.5 and higher
| S_TYPE | V_TYPE |
| ------- | ------------------------------------------------ |
| S_COVER | V_UP, V_DOWN, V_STOP, [V_PERCENTAGE or V_STATUS] |
All V_TYPES above are required. Use V_PERCENTAGE (or V_DIMMER) if you know the exact position of the cover in percent, use V_STATUS (or V_LIGHT) if you don't.
For more information, visit the [serial API](https://www.mysensors.org/download/serial_api_20) of MySensors.
## Example sketch
```cpp
/*
* Documentation: https://www.mysensors.org
* Support Forum: https://forum.mysensors.org
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
#define MY_RADIO_NRF24
#include <MySensors.h>
#define SN "Cover"
#define SV "1.1"
// Actuators for moving the cover up and down respectively.
#define COVER_UP_ACTUATOR_PIN 2
#define COVER_DOWN_ACTUATOR_PIN 3
// Sensors for finding out when the cover has reached its up/down position.
// These could be simple buttons or linear hall sensors.
#define COVER_UP_SENSOR_PIN 4
#define COVER_DOWN_SENSOR_PIN 5
#define CHILD_ID 0
// Internal representation of the cover state.
enum State {
IDLE,
UP, // Window covering. Up.
DOWN, // Window covering. Down.
};
static int state = IDLE;
static int status = 0; // 0=cover is down, 1=cover is up
static bool initial_state_sent = false;
MyMessage upMessage(CHILD_ID, V_UP);
MyMessage downMessage(CHILD_ID, V_DOWN);
MyMessage stopMessage(CHILD_ID, V_STOP);
MyMessage statusMessage(CHILD_ID, V_STATUS);
void sendState() {
// Send current state and status to gateway.
send(upMessage.set(state == UP));
send(downMessage.set(state == DOWN));
send(stopMessage.set(state == IDLE));
send(statusMessage.set(status));
}
void setup() {
pinMode(COVER_UP_SENSOR_PIN, INPUT);
pinMode(COVER_DOWN_SENSOR_PIN, INPUT);
}
void presentation() {
sendSketchInfo(SN, SV);
present(CHILD_ID, S_COVER);
}
void loop() {
if (!initial_state_sent) {
sendState();
initial_state_sent = true;
}
if (state == IDLE) {
digitalWrite(COVER_UP_ACTUATOR_PIN, LOW);
digitalWrite(COVER_DOWN_ACTUATOR_PIN, LOW);
}
if (state == UP && digitalRead(COVER_UP_SENSOR_PIN) == HIGH) {
Serial.println("Cover is up.");
// Update status and state; send it to the gateway.
status = 1;
state = IDLE;
sendState();
// Actuators will be disabled in next loop() iteration.
}
if (state == DOWN && digitalRead(COVER_DOWN_SENSOR_PIN) == HIGH) {
Serial.println("Cover is down.");
// Update status and state; send it to the gateway.
status = 0;
state = IDLE;
sendState();
// Actuators will be disabled in next loop() iteration.
}
}
void receive(const MyMessage &message) {
if (message.type == V_UP) {
// Set state to covering up and send it back to the gateway.
state = UP;
sendState();
Serial.println("Moving cover up.");
// Activate actuator until the sensor returns HIGH in loop().
digitalWrite(COVER_UP_ACTUATOR_PIN, HIGH);
}
if (message.type == V_DOWN) {
// Set state to covering up and send it back to the gateway.
state = DOWN;
sendState();
Serial.println("Moving cover down.");
// Activate actuator until the sensor returns HIGH in loop().
digitalWrite(COVER_DOWN_ACTUATOR_PIN, HIGH);
}
if (message.type == V_STOP) {
// Set state to idle and send it back to the gateway.
state = IDLE;
sendState();
Serial.println("Stopping cover.");
// Actuators will be switched off in loop().
}
}
```
## Sketch example with position measurement based on motor running time
This sketch is ideally for star topology wiring. You can run up to 12 covers with a single Arduino Mega board and some relays. All you need to set is one line of parameters for one Cover. However, you can also use it for a single cover based on an Arduino Nano or even an ESP8266 board.
[Check out the code on GitHub.](https://github.com/gryzli133/RollerShutterSplit)

View File

@ -1,97 +0,0 @@
---
title: "MySensors Device Tracker"
description: "Instructions on how to use MySensors to track devices in Home Assistant."
ha_category:
- DIY
- Presence Detection
ha_release: 0.38
ha_iot_class: Local Push
ha_domain: mysensors
---
Integrates MySensors device trackers into Home Assistant. See the [main integration](/integrations/mysensors/) 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](https://www.mysensors.org/download) of MySensors.
## MySensors 2.x example sketch
```cpp
/**
* Documentation: https://www.mysensors.org
* Support Forum: https://forum.mysensors.org
*
* https://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 <MySensors.h>
#define SN "GPS Sensor"
#define SV "1.0"
// GPS position send interval (in milliseconds)
#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;
}
}
```

View File

@ -1,243 +0,0 @@
---
title: "MySensors Light"
description: "Instructions on how to integrate MySensors lights into Home Assistant."
ha_category:
- DIY
- Light
ha_release: 0.13
ha_iot_class: Local Push
ha_domain: mysensors
---
Integrates MySensors lights into Home Assistant. See the [main integration](/integrations/mysensors/) for configuration instructions.
The following actuator types are supported:
## MySensors version 1.4
| S_TYPE | V_TYPE |
| -------- | --------------------- |
| S_DIMMER | V_DIMMER\*, V_LIGHT\* |
## MySensors version 1.5 and higher
| S_TYPE | V_TYPE |
| ------------ | -------------------------------------------------------------- |
| S_DIMMER | [V_DIMMER\* or V_PERCENTAGE\*], [V_LIGHT\* or V_STATUS\*] |
| S_RGB_LIGHT | V_RGB*, [V_LIGHT\* or V_STATUS\*], [V_DIMMER or V_PERCENTAGE] |
| S_RGBW_LIGHT | V_RGBW*, [V_LIGHT\* or V_STATUS\*], [V_DIMMER or V_PERCENTAGE] |
V_TYPES with a star (\*) denote V_TYPES that should be sent at sketch startup. For an S_DIMMER, send both a V_DIMMER/V_PERCENTAGE and a V_LIGHT/V_STATUS message. For an S_RGB_LIGHT, send both a V_RGB and a V_LIGHT/V_STATUS message with a V_DIMMER/V_PERCENTAGE message being optional. Same principal applies for S_RGBW_LIGHT and V_RGBW.
Sketch should acknowledge a command sent from controller with the same type. If command invokes a change to off state (including a V_PERCENTAGE, V_RGB, or V_RGBW message of zero), only a V_STATUS of zero message should be sent. See sketches below for examples.
For more information, visit the [serial API](https://www.mysensors.org/download) of MySensors.
## MySensors 1.x example sketch
```cpp
/*
* Documentation: https://www.mysensors.org
* Support Forum: https://forum.mysensors.org
*
* https://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));
}
}
```
## MySensors 2.x example sketch
```cpp
/*
* Example Dimmable Light
* Code adapted from https://github.com/mysensors/MySensors/tree/master/examples/DimmableLight
*
* Documentation: https://www.mysensors.org
* Support Forum: https://forum.mysensors.org
*
*/
// Enable debug prints
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensors.h>
#define CHILD_ID_LIGHT 1
#define LIGHT_OFF 0
#define LIGHT_ON 1
#define SN "Dimmable Light"
#define SV "1.0"
int16_t last_state = LIGHT_ON;
int16_t last_dim = 100;
MyMessage light_msg( CHILD_ID_LIGHT, V_STATUS );
MyMessage dimmer_msg( CHILD_ID_LIGHT, V_PERCENTAGE );
void setup()
{
update_light();
Serial.println( "Node ready to receive messages..." );
}
void loop()
{
//In MySensors2.x, first message must come from within loop()
static bool first_message_sent = false;
if ( first_message_sent == false ) {
Serial.println( "Sending initial state..." );
send_dimmer_message();
send_status_message();
first_message_sent = true;
}
}
void presentation()
{
// Send the sketch version information to the gateway
sendSketchInfo( SN, SV );
present( CHILD_ID_LIGHT, S_DIMMER );
}
void receive(const MyMessage &message)
{
//When receiving a V_STATUS command, switch the light between OFF
//and the last received dimmer value
if ( message.type == V_STATUS ) {
Serial.println( "V_STATUS command received..." );
int lstate = message.getInt();
if (( lstate < 0 ) || ( lstate > 1 )) {
Serial.println( "V_STATUS data invalid (should be 0/1)" );
return;
}
last_state = lstate;
//If last dimmer state is zero, set dimmer to 100
if (( last_state == LIGHT_ON ) && ( last_dim == 0 )) {
last_dim=100;
}
//Update constroller status
send_status_message();
} else if ( message.type == V_PERCENTAGE ) {
Serial.println( "V_PERCENTAGE command received..." );
int dim_value = constrain( message.getInt(), 0, 100 );
if ( dim_value == 0 ) {
last_state = LIGHT_OFF;
//Update constroller with dimmer value & status
send_dimmer_message();
send_status_message();
} else {
last_state = LIGHT_ON;
last_dim = dim_value;
//Update constroller with dimmer value
send_dimmer_message();
}
} else {
Serial.println( "Invalid command received..." );
return;
}
//Here you set the actual light state/level
update_light();
}
void update_light()
{
//For this example, just print the light status to console.
if ( last_state == LIGHT_OFF ) {
Serial.println( "Light state: OFF" );
} else {
Serial.print( "Light state: ON, Level: " );
Serial.println( last_dim );
}
}
void send_dimmer_message()
{
send( dimmer_msg.set( last_dim ) );
}
void send_status_message()
{
if ( last_state == LIGHT_OFF ) {
send( light_msg.set( (int16_t)0) );
} else {
send( light_msg.set( (int16_t)1) );
}
}
```

File diff suppressed because it is too large Load Diff

View File

@ -1,93 +0,0 @@
---
title: "MySensors Notify"
description: "Instructions on how to integrate MySensors notifications into Home Assistant."
ha_category:
- DIY
- Notifications
ha_release: 0.36
ha_iot_class: Local Push
ha_domain: mysensors
---
Integrates MySensors notifications into Home Assistant. See the [main integration](/integrations/mysensors/) for configuration instructions.
Setting the `target` key in the service call will target the name of the MySensors device in Home Assistant. MySensors device names follow the notation: "[Sketch name] [Node id] [Child id]".
## Automation example
```yaml
...
action:
service: notify.mysensors
data:
message: Welcome home!
target: "TextSensor 254 1"
```
The following sensor types are supported:
##### MySensors version 2.0 and higher
| S_TYPE | V_TYPE |
| ------ | ------ |
| S_INFO | V_TEXT |
For more information, visit the [API](https://www.mysensors.org/download/) page of MySensors.
### Example sketch
```cpp
/*
* Documentation: https://www.mysensors.org
* Support Forum: https://forum.mysensors.org
*/
#define MY_DEBUG
#define MY_RADIO_NRF24
#define MY_REPEATER_FEATURE
#include <SPI.h>
#include <MySensors.h>
#define SN "TextSensor"
#define SV "1.0"
#define CHILD_ID 1
MyMessage textMsg(CHILD_ID, V_TEXT);
bool initialValueSent = false;
void setup(void) {
}
void presentation() {
sendSketchInfo(SN, SV);
present(CHILD_ID, S_INFO, "TextSensor1");
}
void loop() {
if (!initialValueSent) {
Serial.println("Sending initial value");
// Send initial values.
send(textMsg.set("-"));
Serial.println("Requesting initial value from controller");
request(CHILD_ID, V_TEXT);
wait(2000, C_SET, V_TEXT);
}
}
void receive(const MyMessage &message) {
if (message.type == V_TEXT) {
if (!initialValueSent) {
Serial.println("Receiving initial value from controller");
initialValueSent = true;
}
// Dummy print
Serial.print("Message: ");
Serial.print(message.sensor);
Serial.print(", Message: ");
Serial.println(message.getString());
// Send message to controller
send(textMsg.set(message.getString()));
}
}
```

View File

@ -1,181 +0,0 @@
---
title: "MySensors Sensor"
description: "Instructions on how to integrate MySensors sensors into Home Assistant."
ha_category:
- DIY
- Sensor
ha_iot_class: Local Push
ha_release: 0.7
ha_domain: mysensors
---
Integrates MySensors sensors into Home Assistant. See the [main integration](/integrations/mysensors/) for configuration instructions.
## Supported sensor types
The following sensor types are supported:
### MySensors version 1.4 and higher
| S_TYPE | V_TYPE |
| ------------------ | -------------------------------------- |
| S_TEMP | V_TEMP |
| S_HUM | V_HUM |
| S_BARO | V_PRESSURE, V_FORECAST |
| S_WIND | V_WIND, V_GUST, V_DIRECTION |
| S_RAIN | V_RAIN, V_RAINRATE |
| S_UV | V_UV |
| S_WEIGHT | V_WEIGHT, V_IMPEDANCE |
| S_POWER | V_WATT, V_KWH |
| S_DISTANCE | V_DISTANCE |
| S_LIGHT_LEVEL | V_LIGHT_LEVEL |
| S_IR | V_IR_RECEIVE |
| S_WATER | V_FLOW, V_VOLUME |
| S_AIR_QUALITY | V_DUST_LEVEL |
| S_CUSTOM | V_VAR1, V_VAR2, V_VAR3, V_VAR4, V_VAR5 |
| S_DUST | V_DUST_LEVEL |
| S_SCENE_CONTROLLER | V_SCENE_ON, V_SCENE_OFF |
### MySensors version 1.5 and higher
| S_TYPE | V_TYPE |
| -------------- | --------------------------------- |
| S_COLOR_SENSOR | V_RGB |
| S_MULTIMETER | V_VOLTAGE, V_CURRENT, V_IMPEDANCE |
| S_SOUND | V_LEVEL |
| S_VIBRATION | V_LEVEL |
| S_MOISTURE | V_LEVEL |
| S_LIGHT_LEVEL | V_LEVEL |
| S_AIR_QUALITY | V_LEVEL (replaces V_DUST_LEVEL) |
| S_DUST | V_LEVEL (replaces V_DUST_LEVEL) |
### MySensors version 2.0 and higher
| S_TYPE | V_TYPE |
| --------------- | ------------------------- |
| S_INFO | V_TEXT |
| S_GAS | V_FLOW, V_VOLUME |
| S_GPS | V_POSITION |
| S_WATER_QUALITY | V_TEMP, V_PH, V_ORP, V_EC |
## Custom unit of measurement
Some sensor value types are not specific for a certain sensor type. These do not have a default unit of measurement in Home Assistant. For example, the V_LEVEL type can be used for different sensor types, dust, sound, vibration etc.
By using V_UNIT_PREFIX, it's possible to set a custom unit for any sensor. The string value that is sent for V_UNIT_PREFIX will be used in preference to any other unit of measurement, for the defined sensors. V_UNIT_PREFIX can't be used as a stand-alone sensor value type. Sending a supported value type and value from the tables above is also required. V_UNIT_PREFIX is available with MySensors version 1.5 and later.
For more information, visit the [serial API](https://www.mysensors.org/download) of MySensors.
## Example sketches
### MySensors 1.5 example sketch
```cpp
/**
* Documentation: https://www.mysensors.org
* Support Forum: https://forum.mysensors.org
*
* https://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);
}
```
### MySensors 2.x example sketch
```cpp
/**
* Documentation: https://www.mysensors.org
* Support Forum: https://forum.mysensors.org
*
* https://www.mysensors.org/build/light
*/
#define MY_DEBUG
#define MY_RADIO_NRF24
#include <BH1750.h>
#include <Wire.h>
#include <MySensors.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;
MyMessage msg(CHILD_ID, V_LEVEL);
MyMessage msgPrefix(CHILD_ID, V_UNIT_PREFIX); // Custom unit message.
uint16_t lastlux = 0;
bool initialValueSent = false;
void setup()
{
sendSketchInfo(SN, SV);
present(CHILD_ID, S_LIGHT_LEVEL);
lightSensor.begin();
}
void loop()
{
if (!initialValueSent) {
Serial.println("Sending initial value");
send(msgPrefix.set("custom_lux")); // Set custom unit.
send(msg.set(lastlux));
Serial.println("Requesting initial value from controller");
request(CHILD_ID, V_LEVEL);
wait(2000, C_SET, V_LEVEL);
}
uint16_t lux = lightSensor.readLightLevel(); // Get Lux value
if (lux != lastlux) {
send(msg.set(lux));
lastlux = lux;
}
sleep(SLEEP_TIME);
}
void receive(const MyMessage &message) {
if (message.type == V_LEVEL) {
if (!initialValueSent) {
Serial.println("Receiving initial value from controller");
initialValueSent = true;
}
}
}
```

View File

@ -1,205 +0,0 @@
---
title: "MySensors Switch"
description: "Instructions on how to integrate MySensors switches into Home Assistant."
ha_category:
- DIY
- Switch
ha_iot_class: Local Push
ha_release: 0.11
ha_domain: mysensors
---
Integrates MySensors switches into Home Assistant. See the [main integration](/integrations/mysensors/) for configuration instructions.
## Supported actuator types
The following actuator types are supported:
### MySensors version 1.4 and higher
| S_TYPE | V_TYPE |
| -------- | ------------------ |
| S_DOOR | V_ARMED |
| S_MOTION | V_ARMED |
| S_SMOKE | V_ARMED |
| S_LIGHT | V_LIGHT |
| S_LOCK | V_LOCK_STATUS |
| S_IR | V_IR_SEND, V_LIGHT |
### MySensors version 1.5 and higher
| S_TYPE | V_TYPE |
| ------------ | --------------------- |
| S_LIGHT | V_STATUS |
| S_BINARY | [V_STATUS or V_LIGHT] |
| S_SPRINKLER | V_STATUS |
| S_WATER_LEAK | V_ARMED |
| S_SOUND | V_ARMED |
| S_VIBRATION | V_ARMED |
| S_MOISTURE | V_ARMED |
### MySensors version 2.0 and higher
| S_TYPE | V_TYPE |
| --------------- | -------- |
| S_WATER_QUALITY | V_STATUS |
All V_TYPES for each S_TYPE above are required to activate the actuator for the platform. Use either V_LIGHT or V_STATUS depending on library version for cases where that V_TYPE is required.
For more information, visit the [serial API](https://www.mysensors.org/download) of MySensors.
## Services
The MySensors switch platform exposes a service to change an IR code attribute for an IR switch device and turn the switch on. The IR switch will automatically be turned off after being turned on, if `optimistic` is set to `true` in the [configuration](/integrations/mysensors/#configuration) for the MySensors component. This will simulate a push button on a remote. If `optimistic` is `false`, the MySensors device will have to report its updated state to reset the switch. See the [example sketch](#ir-switch-sketch) for the IR switch below.
| Service | Description |
| ---------------------- | -------------------------------------------------------------------------------------------- |
| mysensors.send_ir_code | Set an IR code as a state attribute for a MySensors IR device switch and turn the switch on. |
The service can be used as part of an automation script. For example:
```yaml
# Example configuration.yaml automation entry
automation:
- alias: "Turn HVAC on"
trigger:
platform: time
at: "5:30:00"
action:
service: mysensors.send_ir_code
target:
entity_id: switch.hvac_1_1
data:
V_IR_SEND: "0xC284" # the IR code to send
- alias: "Turn HVAC off"
trigger:
platform: time
at: "0:30:00"
action:
service: mysensors.send_ir_code
target:
entity_id: switch.hvac_1_1
data:
V_IR_SEND: "0xC288" # the IR code to send
```
## Example sketches
### Switch sketch
```cpp
/*
* Documentation: https://www.mysensors.org
* Support Forum: https://forum.mysensors.org
*
* https://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);
gw.send(msgRelay.set(message.getBool() ? 1 : 0));
}
}
```
### IR switch sketch
```cpp
/*
* Documentation: https://www.mysensors.org
* Support Forum: https://forum.mysensors.org
*
* https://www.mysensors.org/build/ir
*/
#include <MySensor.h>
#include <SPI.h>
#include <IRLib.h>
#define SN "IR Sensor"
#define SV "1.0"
#define CHILD_ID 1
MySensor gw;
char code[10] = "abcd01234";
char oldCode[10] = "abcd01234";
MyMessage msgCodeRec(CHILD_ID, V_IR_RECEIVE);
MyMessage msgCode(CHILD_ID, V_IR_SEND);
MyMessage msgSendCode(CHILD_ID, V_LIGHT);
void setup()
{
gw.begin(incomingMessage);
gw.sendSketchInfo(SN, SV);
gw.present(CHILD_ID, S_IR);
// Send initial values.
gw.send(msgCodeRec.set(code));
gw.send(msgCode.set(code));
gw.send(msgSendCode.set(0));
}
void loop()
{
gw.process();
// IR receiver not implemented, just a dummy report of code when it changes
if (String(code) != String(oldCode)) {
Serial.print("Code received ");
Serial.println(code);
gw.send(msgCodeRec.set(code));
strcpy(oldCode, code);
}
}
void incomingMessage(const MyMessage &message) {
if (message.type==V_LIGHT) {
// IR sender not implemented, just a dummy print.
if (message.getBool()) {
Serial.print("Sending code ");
Serial.println(code);
}
gw.send(msgSendCode.set(message.getBool() ? 1 : 0));
// Always turn off device
gw.wait(100);
gw.send(msgSendCode.set(0));
}
if (message.type == V_IR_SEND) {
// Retrieve the IR code value from the incoming message.
String codestring = message.getString();
codestring.toCharArray(code, sizeof(code));
Serial.print("Changing code to ");
Serial.println(code);
gw.send(msgCode.set(code));
}
}
```

View File

@ -94,39 +94,39 @@
/components/alexa.intent /integrations/alexa.intent
/components/alexa.smart_home /integrations/alexa.smart_home
/components/binary_sensor.mqtt /integrations/binary_sensor.mqtt
/components/binary_sensor.mysensors /integrations/binary_sensor.mysensors
/components/binary_sensor.mysensors /integrations/mysensors#binary-sensor
/components/binary_sensor.rest /integrations/binary_sensor.rest
/components/binary_sensor.rflink /integrations/binary_sensor.rflink
/components/camera.mqtt /integrations/camera.mqtt
/components/climate.mqtt /integrations/climate.mqtt
/components/climate.mysensors /integrations/climate.mysensors
/components/climate.mysensors /integrations/mysensors#climate
/components/cover.command_line /integrations/cover.command_line
/components/cover.group /integrations/cover.group
/components/cover.mqtt /integrations/cover.mqtt
/components/cover.mysensors /integrations/cover.mysensors
/components/cover.mysensors /integrations/mysensors#cover
/components/cover.template /integrations/cover.template
/components/device_tracker.mqtt /integrations/device_tracker.mqtt
/components/device_tracker.mysensors /integrations/device_tracker.mysensors
/components/device_tracker.mysensors /integrations/mysensors#device-tracker
/components/fan.mqtt /integrations/fan.mqtt
/components/fan.template /integrations/fan.template
/components/light.group /integrations/light.group
/components/light.mqtt /integrations/light.mqtt
/components/light.mysensors /integrations/light.mysensors
/components/light.mysensors /integrations/mysensors#light
/components/light.switch /integrations/light.switch
/components/light.template /integrations/light.template
/components/lock.mqtt /integrations/lock.mqtt
/components/lock.template /integrations/lock.template
/components/notify.command_line /integrations/notify.command_line
/components/notify.group /integrations/notify.group
/components/notify.mysensors /integrations/notify.mysensors
/components/notify.mysensors /integrations/mysensors#notify
/components/notify.rest /integrations/notify.rest
/components/public_sensor.netatmo /integrations/netatmo
/components/sensor.command_line /integrations/sensor.command_line
/components/sensor.mqtt /integrations/sensor.mqtt
/components/sensor.mysensors /integrations/sensor.mysensors
/components/sensor.mysensors /integrations/mysensors#sensor
/components/switch.command_line /integrations/switch.command_line
/components/switch.mqtt /integrations/switch.mqtt
/components/switch.mysensors /integrations/switch.mysensors
/components/switch.mysensors /integrations/mysensors#switch
/components/switch.rest /integrations/switch.rest
/components/switch.template /integrations/switch.template
/components/telegram_bot.broadcast /integrations/telegram_broadcast