From 0877304910091024557367b9a33304e3272836fc Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Mon, 13 Jun 2016 22:44:10 +0200 Subject: [PATCH] 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. --- source/_components/sensor.mysensors.markdown | 4 +- source/_components/switch.mysensors.markdown | 113 ++++++++++++++++++- 2 files changed, 113 insertions(+), 4 deletions(-) diff --git a/source/_components/sensor.mysensors.markdown b/source/_components/sensor.mysensors.markdown index 9690ece312b..1420e037279 100644 --- a/source/_components/sensor.mysensors.markdown +++ b/source/_components/sensor.mysensors.markdown @@ -2,7 +2,7 @@ layout: page title: "MySensors Sensor" description: "Instructions how to integrate MySensors sensors into Home Assistant." -date: 2016-04-13 14:20 +0100 +date: 2016-06-12 15:00 +0200 sidebar: true comments: false sharing: true @@ -30,7 +30,7 @@ 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_SEND, V_IR_RECEIVE +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 diff --git a/source/_components/switch.mysensors.markdown b/source/_components/switch.mysensors.markdown index 77944cce9cc..1e9b9a11dd0 100644 --- a/source/_components/switch.mysensors.markdown +++ b/source/_components/switch.mysensors.markdown @@ -2,7 +2,7 @@ layout: page title: "MySensors Switch" description: "Instructions how to integrate MySensors switches into Home Assistant." -date: 2016-04-21 13:30 +0100 +date: 2016-06-12 15:00 +0200 sidebar: true comments: false sharing: true @@ -25,6 +25,7 @@ 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 @@ -38,10 +39,47 @@ 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 Example sketch %} +### {% 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](/components/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 + 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 %} ```cpp /* * Documentation: http://www.mysensors.org @@ -86,5 +124,76 @@ void incomingMessage(const MyMessage &message) } ``` +#### {% linkable_title IR switch sketch %} +```cpp +/* + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * http://www.mysensors.org/build/ir + */ + +#include +#include +#include + +#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)); + } +} +``` + [main component]: /components/mysensors/ [serial api]: https://www.mysensors.org/download/serial_api_15