[SOLVED]Getting scene to work

Hallo All,

I have followed this tutoria:

Now i have the red, yellow and blue on button working.
I have the colorwpicker working.
And i have the slider working.

But there also scenes in the arduino code, i would like to have them working too.
I think i need some rule for them to work.

I a’m not sure my items file is correct for the scenes.
And have no rule yet for the scenes.

Can someone please point me in the right direction or tell me how to get it working.

Iff thinks are not clear please let me no.

My items file is:

//https://makezine.com/projects/building-a-home-automation-system-with-openhab-to-control-leds-wirelessly/
Group All
Color RGBLed "NeoPixel Color" (All)
String RGBLedColor (All) {mqtt=">[broker:OpenHab/RGB:command:*:default]"}
Switch NEO_RED  "Red"   <red> {mqtt=">[broker:OpenHab/RGB:command:ON:255,0,0]"}
Switch NEO_YELLOW "Yellow" <yellow> {mqtt=">[broker:OpenHab/RGB:command:ON:100,96,0]"}
Switch NEO_BLUE "Blue" <darkblue> {mqtt=">[broker:OpenHab/RGB:command:ON:0,0,255]"}

Switch NEO_RAINBOWCYCLE "Rainbowcycle" <rainbowcycle> {mqtt=">[broker:OpenHab/RGB/scene:commend:ON]"}
Switch NEO_RAINBOWTHEATER "Rainbowtheater" <rainbowtheater> {mqtt=">[broker:OpenHab/RGB/scene:commend:ON]"}


Dimmer NEO_SLIDERRED "Neopixel Red [%d %%]"  <red> {mqtt=">[broker:OpenHab/RGB/RED:command:*:default]"}
Dimmer NEO_SLIDERGREEN "Neopixel Green [%d %%]" <green> {mqtt=">[broker:OpenHab/RGB/GREEN:command:*:default]"}
Dimmer NEO_SLIDERBLUE "Neopixel Blue [%d %%]" <blue> {mqtt=">[broker:OpenHab/RGB/BLUE:command:*:default]"}

Number W_RSSI  "RSSI [%d dbm]" <signal>  {mqtt="<[broker:home/nb/weer/RSSI:state:default]"}
String W_IP "IP [%s]" <network>   {mqtt="<[broker:home/nb/weer/IP:state:default]"}
String W_version "Software versie [%s]" <version>  {mqtt="<[broker:home/nb/weer/version:state:default]"}
String W_MAC "MAC [%s]" <mac> (Wweather) {mqtt="<[broker:home/nb/weer/mac:state:default]"}
Number W_IP_Uptime "Uptime [%d min]" <clock> (Wweather) {mqtt="<[broker:home/nb/weer/uptime:state:default]"}

My rules file is:

import org.eclipse.smarthome.core.library.types.DecimalType
import org.eclipse.smarthome.core.library.types.HSBType

rule “Set HSB value of item RGBLed to RGB color value”
when
Item RGBLed changed
then
val hsbValue = RGBLed.state as HSBType

val brightness = hsbValue.brightness.intValue
val redValue = ((((hsbValue.red.intValue * 255) / 100) *brightness) /100).toString
val greenValue = ((((hsbValue.green.intValue * 255) / 100) *brightness) /100).toString
val blueValue = ((((hsbValue.blue.intValue * 255) / 100) *brightness) /100).toString

val color = redValue + "," + greenValue + "," + blueValue

sendCommand( RGBLedColor, color)

end

//part of Neopixel conf files

rule “Send RGB items from slider”
when
Item NEO_SLIDERRED changed or
Item NEO_SLIDERGREEN changed or
Item NEO_SLIDERBLUE changed
then
val redValue= Math::round(2.55* (NEO_SLIDERRED.state as DecimalType).intValue)
val greenValue= Math::round(2.55* (NEO_SLIDERGREEN.state as DecimalType).intValue) //
val blueValue= Math::round(2.55* (NEO_SLIDERBLUE.state as Number).intValue)
val color = redValue + “,” + greenValue + “,” + blueValue
sendCommand( RGBLedColor, color)
end

My sitemap file is:

sitemap NeoPixel label="NeoPixel"
{
    Frame label="NeoPixel" {
        Colorpicker item=RGBLed icon="slider"
        //-----
Switch item=NEO_RED mappings=[ON="ON"]
Switch item=NEO_YELLOW mappings=[ON="ON"]
Switch item=NEO_BLUE mappings=[ON="ON"]

Switch item=NEO_RAINBOWCYCLE mappings=[ON="ON"]
Switch item=NEO_RAINBOWTHEATER mappings=[ON="ON"]

Slider item=NEO_SLIDERRED
Slider item=NEO_SLIDERGREEN
Slider item=NEO_SLIDERBLUE
        //-----
}

Frame label="Info" {

Text item=W_RSSI
   Text item=W_IP
   Text item=W_version
   Text item=W_MAC
   Text item=W_IP_Uptime
}
}

The arduino code has 4 tabs
first tab:

//NeoPixelOpenHab
//loosely based on https://makezine.com/projects/building-a-home-automation-system-with-openhab-to-control-leds-wirelessly/
//Change the color of a NeoPixel Strip using OpenHab and MQTT!
//Uses the PubSubClient library located at https://github.com/Imroy/pubsubclient

#include “Adafruit_NeoPixel.h”
#include “ESP8266WiFi.h”
#include “PubSubClient.h” //Imroy
#include “userdata.h”

/* Adafruit NeoPixel Settings */

#define PIXEL_PIN 2 // Digital IO pin connected to the NeoPixels. that is D4

#define PIXEL_COUNT 43 // 60 pixels in the NeoPixel strip

// Parameter 1 = number of pixels in strip, neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick & rings
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

/* MQTT Topic Settings /
// Enter the topic for your LED strip
String topic = “OpenHab/RGB/#”;//this is your ‘catch all’ for MQTT topics
String IP;
String MAC;
/
Network Settings */
// Change for your WiFi network. DO NOT CHANGE HERE, CHANGE IN “userdata” tab
const char *ssid = mySSID; // cannot be longer than 32 characters!
const char *pass = PASSW; //

// Update these with values suitable for your network.
IPAddress server( myMQTT); //ipaddres MQTT server

// STARTUP DEFAULTS
long TXinterval = TRANSMITINTERVAL; // can set this in userdata.h
int signalStrength; // WiFi signal strength
long lastMinute = -1; // timestamp last minute
long upTime = 0; // uptime in minutes
byte scene;

// Initializes the color to zero
uint32_t color = 0;

// Initializes update status to false
volatile bool updateLights = false;

#define BUFFER_SIZE 100

// OTA configuration
//
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

const char* host = HOST; //set this in userdata.h
// function prototypes required by Arduino IDE 1.6.7, but we are now way passed that
void setupOTA(void);
//--------------------------------

void callback(const MQTT::Publish & pub) {
if (pub.has_stream()) {
uint8_t buf[BUFFER_SIZE];
int read;
while (read = pub.payload_stream()->read(buf, BUFFER_SIZE)) {
Serial.write(buf, read);
}
pub.payload_stream()->stop();
Serial.println("*");
} else
Serial.print(pub.topic());
Serial.print(" ");
Serial.println(pub.payload_string());
//----------------
// Check if the control topic came in and split payload into R,G,B values
if (pub.topic() == “OpenHab/RGB”) {
String values = pub.payload_string();
int c1 = pub.payload_string().indexOf(’,’);
int c2 = pub.payload_string().indexOf(’,’, c1 + 1);
int red = pub.payload_string().toInt();
int green = pub.payload_string().substring(c1 + 1).toInt();
int blue = pub.payload_string().substring(c2 + 1).toInt();
color = strip.Color(red, green, blue);
updateLights = true;
scene=0;
} else {
// check if a scene setting topic came in
if (pub.topic() == “OpenHab/RGB/scene”) {

  scene=pub.payload_string().toInt();
}

}
//------------------

}

WiFiClient wclient;
PubSubClient client(wclient, server);

void setup() {
// Setup console
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
strip.begin();
setupOTA();
MAC = WiFi.macAddress();
}

void changeColor(uint32_t c) {
if (updateLights) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
updateLights = false;
}
}
}

void loop() {

if (WiFi.status() != WL_CONNECTED) {
Serial.print(“Connecting to “);
Serial.print(ssid);
Serial.println(”…”);
WiFi.begin(ssid, pass);

if (WiFi.waitForConnectResult() != WL_CONNECTED)
  return;
Serial.println("WiFi connected");

}

if (WiFi.status() == WL_CONNECTED) {
if (!client.connected()) {
if (client.connect(“arduinoClient”)) {
client.set_callback(callback);
client.subscribe(topic);
}
}
}
if (client.connected())
client.loop();
changeColor(color);
//-----
if (millis() % (TXinterval * 1000) == 0) {
client.publish(“home/nb/weer/version”, VERSION); // no quotes or “String” as it is a macro
signalStrength = WiFi.RSSI();
client.publish(“home/nb/weer/RSSI”, String(signalStrength));// these topics are my choice, can change them, but then do as well in yr itemsfile
IP = WiFi.localIP().toString();
client.publish(“home/nb/weer/IP”, String(IP));
client.publish(“home/nb/weer/mac”, String(MAC));
client.publish(“home/nb/weer/uptime”, String(upTime));
//Serial.println(MAC);
}
// INCREASE UPTIME

if (lastMinute != (millis() / 60000)) { // another minute passed ?
lastMinute = millis() / 60000;
upTime++;
}
switch (scene) {
case 1: rainbow(20);
break;
case 2: redblue();
break;
case 3: bluedot();
break;
case 4: rainbowCycle(20);
break;
case 5:theaterChaseRainbow(50);
break;
}
}

Second tab:

//
// OTA set up and events
//
void setupOTA(void)
{
  ArduinoOTA.setHostname(host);
//ArduinoOTA.setPassword((const char *)"123");
  ArduinoOTA.onStart([]() {
    Serial.println("OTA upload start");
    // switch strip off in case OTA fails
  

  });

  ArduinoOTA.onEnd([]() {
    //Serial.println("OTA upload end");
    //Serial.println("Restarting...");
  });

  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  });

  ArduinoOTA.begin();
 // Serial.println("OTA initialized");
}

third tab:

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256; j++) {
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}


// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
  Serial.println(j);
}


//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
        Serial.print("i= ");
          Serial.println(i);
      }
    }
    Serial.print("j= ");
    Serial.println(j);
  }
}

void redblue()//redblue
{
  for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, 0xFF0000); //Red
    strip.show();
    i++;
    strip.setPixelColor(i, 0xFF); //Blue
    strip.show();
  }
}


void bluedot() {
  //first make red
  updateLights = true;
  color = strip.Color(255, 0, 0);
  changeColor(color);
  byte aantal = random(60);

  for (uint16_t i = 0; i < 61
       ; i++) {
    strip.setPixelColor(i, 0x551111);
    strip.show();
    //delay(500);
    strip.setPixelColor(i - 1, 0xFF0000);
    strip.show();
    delay(50);
  }
}

void scene3()
{
  Serial.println("weather");
}

void scene4()
{
  Serial.println("pattern");
}

void scene5()
{
  Serial.println("wa");
}




// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

fourt tab

#define VERSION "NeopixelOpenHab" // the filename
#define HOST  "OTA-Neopixel" //your OTA identifier
#define PASSW "My WiFi Passwd"
#define mySSID "My SSID"
#define myMQTT My Ip of Mosquitto ///<--your MQTT server address. mind you, it has comma separation, not dots
#define TRANSMITINTERVAL 10 // how often do you want the program to  send back info

Well, if I understand correctly, you don’t get the device-built-in programs to work.
First, please don’t call that a ‘scene’. A scene rather means to control multiple devices (of same or even different technology) in a coordinated fashion such as to say set the same light color on multiple lamps in a single go.

On the openHAB part, I don’t see anything wrong with it except that you have a typo in the MQTT parameters of the switch items that I assume you want to use to activate those colorcycle programs
(“commend” instead of “command”). Maybe changing that helps.
If not, you would need to debug your device to find out what it does when it receives the MQTT command (now as you say the color switches work I assume that MQTT commands do correctly arrive).
Now that is a specific problem with that device you’re using and unrelated to openHAB.
I guess few people here will ever even just have heard of that device, so you would probably be better off to ask elsewhere such as on the forum you quoted.

Thanks for the reply.
I fixed the typo. Well i now no that the openhab part is good. Will post on the esp forum.

Greet