euphi / BalkonController

ESP8266 Irrigation control with 4 + 1 valves, a pump and as bonus RGB/White LED-Strip
9 stars 2 forks source link

RGBW cpp & h #2

Open lesjaw opened 7 years ago

lesjaw commented 7 years ago

Hi.. I am so interested with your RGBW code.. is there a way I can use it for homie? can you give the ino sample code.. thank you

euphi commented 7 years ago

The latest version of RGWNode class is available at my Node Collection and depends on the latestDevelopment version of Homie V2-Branch.

See the files at https://github.com/euphi/HomieNodeCollection/blob/master/src/RGBWNode.cpp and https://github.com/euphi/HomieNodeCollection/blob/master/src/RGBWNode.h .

They support an OLED display to show current values. If you don't want to use it, you can just remove any references to OLEDFrame and OLEDOverlay in .h and .cpp.

    // OLEDFrame
    virtual void drawFrame(OLEDDisplay& display,  OLEDDisplayUiState& state, int16_t x, int16_t y) override;

    // OLEDOverlay
    virtual void drawOverlay(OLEDDisplay& display,  OLEDDisplayUiState& state, uint8_t idx) override;

The node also uses MQTT for logging with the LogggerNode class. Either just use LoggerNode or remove any reference to it (e.g any calls to LN.logf(..)).

You can configure the Output PINS in the .h file:

enum RGBW_PINMAP {
        REDPIN = 12, GREENPIN = 13, BLUEPIN = 14, WHITEPIN = 16
};

The Node expects a MQTT message

devices/your_device_id/LED/r/set value devices/your_device_id/LED/g/set value devices/your_device_id/LED/b/set value devices/your_device_id/LED/w/set value

(value = 0-100%)

I will add an example OpenHAB configuration soon (I'm not at home, so I don't have access to the config files).

euphi commented 7 years ago

Example openhab (Version 1) item configuration (e.g. mqtt.items):

Group Rooms
Group Kueche (Rooms)

// Küche
Color  kueche_led       "Unterbau"      <slider>    (Kueche)
Dimmer kueche_led_R     "Rot [%d %%]"   <switch>    (Kueche)        {mqtt=">[local:devices/kueche/LED/r/set:state:*:default]"}
Dimmer kueche_led_G     "Grün [%d %%]" <switch>    (Kueche)        {mqtt=">[local:devices/kueche/LED/g/set:state:*:default]"}
Dimmer kueche_led_B     "Blau [%d %%]"  <switch>    (Kueche)        {mqtt=">[local:devices/kueche/LED/b/set:state:*:default]"}
Dimmer kueche_led_W     "Weiß [%d %%]" <slider>    (Kueche)        {mqtt=">[local:devices/kueche/LED/w/set:command:*:default]"}

Example sitemap configuraion, e.g. default.sitemap:

Frame label="Küche" {
      Colorpicker item=kueche_led icon="slider"
      Slider item=kueche_led_W label="Weiß"
  }

Example rule (e.g. rgb.rules) to calculate RGB values from Color (Colorpicker) item and post update:

rule "Set Kueche RGB value"
   when
   Item kueche_led changed
   then
   hsbValue = kueche_led.state as HSBType 

   redValue = hsbValue.red.intValue
   greenValue = hsbValue.green.intValue
   blueValue = hsbValue.blue.intValue

   postUpdate(kueche_led_R, redValue)
   postUpdate(kueche_led_G, greenValue)
   postUpdate(kueche_led_B, blueValue)

   RGBvalues= "Values" + redValue.toString + ";" + greenValue.toString + ";" + blueValue.toString
   logInfo( "kueche_led", RGBvalues )

end
lesjaw commented 7 years ago

Hallo Ian.. I have check the file, but can you give me the example ino file (arduino file)?

all i have to is to put these two file https://github.com/euphi/ HomieNodeCollection/blob/master/src/RGBWNode.cpp and https://github.com/euphi/HomieNodeCollection/blob/master/src/RGBWNode.h in homie library folder right? https://github.com/euphi/HomieNodeCollection/blob/master/src/RGBWNode.h

On Sat, Oct 1, 2016 at 2:58 PM, Ian Hubbertz notifications@github.com wrote:

Example openhab (Version 1) item configuration (e.g. mqtt.items):

Group Rooms Group Kueche (Rooms)

// Küche Color kueche_led "Unterbau" (Kueche) Dimmer kueche_ledR "Rot [%d %%]" (Kueche) {mqtt=">[local:devices/kueche/LED/r/set:state::default]"} Dimmer kueche_ledG "Grün [%d %%]" (Kueche) {mqtt=">[local:devices/kueche/LED/g/set:state::default]"} Dimmer kueche_ledB "Blau [%d %%]" (Kueche) {mqtt=">[local:devices/kueche/LED/b/set:state::default]"} Dimmer kueche_ledW "Weiß [%d %%]" (Kueche) {mqtt=">[local:devices/kueche/LED/w/set:command::default]"}

Example sitemap configuraion, e.g. default.sitemap:

Frame label="Küche" { Colorpicker item=kueche_led icon="slider" Slider item=kueche_led_W label="Weiß" }

Example rule (e.g. rgb.rules) to calculate RGB values from Color (Colorpicker) item and post update:

rule "Set Kueche RGB value" when Item kueche_led changed then hsbValue = kueche_led.state as HSBType

redValue = hsbValue.red.intValue greenValue = hsbValue.green.intValue blueValue = hsbValue.blue.intValue

postUpdate(kueche_led_R, redValue) postUpdate(kueche_led_G, greenValue) postUpdate(kueche_led_B, blueValue)

RGBvalues= "Values" + redValue.toString + ";" + greenValue.toString + ";" + blueValue.toString logInfo( "kueche_led", RGBvalues )

end

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/euphi/BalkonController/issues/2#issuecomment-250899213, or mute the thread https://github.com/notifications/unsubscribe-auth/AMCmp5bRoSn0xLDZCYqCC_J5FAO2yqj9ks5qvhKrgaJpZM4KKwsf .