|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: "MySensors HVAC" |
| 4 | +description: "Instructions how to integrate MySensors climate into Home Assistant." |
| 5 | +date: 2016-09-14 18:20 +0100 |
| 6 | +sidebar: true |
| 7 | +comments: false |
| 8 | +sharing: true |
| 9 | +footer: true |
| 10 | +logo: mysensors.png |
| 11 | +ha_category: Light |
| 12 | +featured: false |
| 13 | +ha_release: 0.28+ |
| 14 | +--- |
| 15 | + |
| 16 | +Integrates MySensors HVAC into Home Assistant. See the [main component] for configuration instructions. |
| 17 | + |
| 18 | +The following actuator types are supported: |
| 19 | + |
| 20 | +##### MySensors version 1.5 and higher |
| 21 | + |
| 22 | +S_TYPE | V_TYPE |
| 23 | +------------|------------- |
| 24 | +S_HVAC | [V_HVAC_SETPOINT_HEAT, V_HVAC_SETPOINT_COLD, V_HVAC_FLOW_STATE, V_HVAC_FLOW_MODE, V_HVAC_SPEED] |
| 25 | + |
| 26 | +For more information, visit the [serial api] of MySensors. |
| 27 | + |
| 28 | +### {% linkable_title Example sketch %} |
| 29 | + |
| 30 | +```cpp |
| 31 | +/* |
| 32 | + * Documentation: http://www.mysensors.org |
| 33 | + * Support Forum: http://forum.mysensors.org |
| 34 | + * |
| 35 | + * http://www.mysensors.org/build/dimmer |
| 36 | + */ |
| 37 | + |
| 38 | +#include <MySensor.h> |
| 39 | +#include <SPI.h> |
| 40 | + |
| 41 | +#define SN "DimmableRGBLED" |
| 42 | +#define SV "1.0" |
| 43 | +#define CHILD_ID 1 |
| 44 | +#define LED_PIN 5 |
| 45 | + |
| 46 | +MySensor gw; |
| 47 | + |
| 48 | +char rgb[7] = "ffffff"; // RGB value. |
| 49 | +int currentLevel = 0; // Current dimmer level. |
| 50 | +MyMessage dimmerMsg(CHILD_ID, V_PERCENTAGE); |
| 51 | +MyMessage lightMsg(CHILD_ID, V_STATUS); |
| 52 | +MyMessage rgbMsg(CHILD_ID, V_RGB); |
| 53 | + |
| 54 | +void setup() |
| 55 | +{ |
| 56 | + gw.begin(incomingMessage); |
| 57 | + gw.sendSketchInfo(SN, SV); |
| 58 | + gw.present(CHILD_ID, S_RGB_LIGHT); |
| 59 | + // Send initial values. |
| 60 | + gw.send(lightMsg.set(currentLevel > 0 ? 1 : 0)); |
| 61 | + gw.send(dimmerMsg.set(currentLevel)); |
| 62 | + gw.send(rgbMsg.set(rgb)); |
| 63 | +} |
| 64 | + |
| 65 | +void loop() |
| 66 | +{ |
| 67 | + gw.process(); |
| 68 | +} |
| 69 | + |
| 70 | +void incomingMessage(const MyMessage &message) { |
| 71 | + if (message.type == V_RGB) { |
| 72 | + // Retrieve the RGB value from the incoming message. |
| 73 | + // RGB LED not implemented, just a dummy print. |
| 74 | + String hexstring = message.getString(); |
| 75 | + hexstring.toCharArray(rgb, sizeof(rgb)); |
| 76 | + Serial.print("Changing color to "); |
| 77 | + Serial.println(rgb); |
| 78 | + gw.send(rgbMsg.set(rgb)); |
| 79 | + } |
| 80 | + |
| 81 | + if (message.type == V_STATUS || message.type == V_PERCENTAGE) { |
| 82 | + // Retrieve the light status or dimmer level from the incoming message. |
| 83 | + int requestedLevel = atoi(message.data); |
| 84 | + |
| 85 | + // Adjust incoming level if this is a V_LIGHT update [0 == off, 1 == on]. |
| 86 | + requestedLevel *= (message.type == V_STATUS ? 100 : 1); |
| 87 | + |
| 88 | + // Clip incoming level to valid range of 0 to 100 |
| 89 | + requestedLevel = requestedLevel > 100 ? 100 : requestedLevel; |
| 90 | + requestedLevel = requestedLevel < 0 ? 0 : requestedLevel; |
| 91 | + |
| 92 | + // Change level value of LED pin. |
| 93 | + analogWrite(LED_PIN, (int)(requestedLevel / 100. * 255)); |
| 94 | + currentLevel = requestedLevel; |
| 95 | + |
| 96 | + // Update the gateway with the current V_STATUS and V_PERCENTAGE. |
| 97 | + gw.send(lightMsg.set(currentLevel > 0 ? 1 : 0)); |
| 98 | + gw.send(dimmerMsg.set(currentLevel)); |
| 99 | + } |
| 100 | +} |
| 101 | +``` |
| 102 | +
|
| 103 | +[main component]: /components/mysensors/ |
| 104 | +[serial api]: https://www.mysensors.org/download/serial_api_15 |
0 commit comments