home-assistant.io/source/_components/switch.mysensors.markdown
Paulus Schoutsen 1f40fdb09d 0.22 (#570)
* Initial snmp sensor docs (#538)

* Fixed markdown and added logo (#551)

* Added documentation for router operating mode for asuswrt (#545)

* local_file camera component documenatation (#554)

* Documenation for local_file camera component

* Update camera.local_file.markdown

* Added information about voltage sensor

* Instructions for Pandora media player (#552)

* Add release

* Add pub_key

* Add BT Home Hub docs

* Markdown tweaks (#553)

* Add docs about MySensors IR switch (#556)

* Update sensor.mysensors docs, about moving V_IR_SEND type to switch
  platform.
* Update switch.mysensors docs. Add section about the new service and
  additional example sketch for the IR switch device.

* Update index.html

* plex sensor (#526)

* Add var descriptions

* Adds documentation for the Local File Camera (#482)

* Revert "Adds documentation for the Local File Camera" (#563)

* Minor changes

* Add Wink Rollershutter (#559)

* Added example of using template in shell_command. (#547)

* Add Documentation for Netatmo Welcome (#542)

* Reorganize  documentation for Netatmo

As Netatmo is now a Hub component, documentations has been splitted in several
parts betweent the hub, the sensors and the camera

Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>

* Add configuration variables for Netatmo Welcome cameras

* Add ha_release information on new documentation pages

* Netatmo Weather Station is a weather sensor

* Add blog post 0.22
2016-06-18 13:24:52 -07:00

5.1 KiB

layout, title, description, date, sidebar, comments, sharing, footer, logo, ha_category, featured
layout title description date sidebar comments sharing footer logo ha_category featured
page MySensors Switch Instructions how to integrate MySensors switches into Home Assistant. 2016-06-12 15:00 +0200 true false true true mysensors.png Switch false

Integrates MySensors switches into Home Assistant. See the main component for configuration instructions.

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

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 of MySensors.

{% linkable_title 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 config 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 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:

# Example configuration.yaml automation entry
automation:
  - alias: turn hvac on
    trigger:
      platform: time
      after: '5:30:00'
    action:
      service: switch.mysensors_send_ir_code
      entity_id: switch.hvac_1_1
      data:
        V_IR_SEND: '0xC284'  # the IR code to send

  - alias: turn hvac off
    trigger:
      platform: time
      after: '0:30:00'
    action:
      service: switch.mysensors_send_ir_code
      entity_id: switch.hvac_1_1
      data:
        V_IR_SEND: '0xC288'  # the IR code to send

{% linkable_title Example sketches %}

{% linkable_title Switch sketch %}

/*
 * 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);
     gw.send(msgRelay.set(message.getBool() ? 1 : 0));
  }
}

{% linkable_title IR switch sketch %}

/*
 * Documentation: http://www.mysensors.org
 * Support Forum: http://forum.mysensors.org
 *
 * http://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));
  }
}