Neopixel and https post and color item

I have got a programmable neopixel ledstrip hooked up to wio link. I have created a color item:
Color neopixel

So whenever this receive a change I would like to do a post request:

https://us.wio.seeed.io/v1/node/GroveLedWs2812D0/clear/3/FFFFFF?access_token=XXXXXXXXXXXX

where the FFFFFF is the rgb value in hex, Which binding should I use to achieve this? Curl and exec or the http binding? How to can I convert the hsbvalue from the color item to HEX value?

HTTP binding would be my first choice.

I think HSBType has a toHex method. I don’t do color so don’t know for sure but I’m certain others have posted similar code on this forum.

If you use Designer you can press crtl-space and it will give you all the methods on the HSBType.

Well it seems like hsbvalue does not have a hex method…

How can I just execute a command from a rule without having an item?

rule "Set RGB value Kitchen"
    when
        Item Color_Kitchen changed
    then
    var HSBType hsbValueKitchen  
   var String hexString
   
    hsbValueKitchen = Color_Kitchen.state as HSBType
    logInfo("Info", hsbValueKitchen.toString())
    hexString = Integer::toHexString( hsbValueKitchen.red ) + Integer::toHexString( hsbValueKitchen.green ) + Integer::toHexString( hsbValueKitchen.blue )	
    //exec="<[curl -k -X POST https://us.wio.seeed.io/v1/node/GroveLedWs2812D0/clear/3/FFFFFF?access_token=MyTokene]"
    
    
end

executeCommandLine("cmd", 5000)

Trying differnet things, i added both the 1.9 exec and the 2.0 but none of them seems to work for me…

    hexValue = Integer::toHexString( (hsbValueKitchen.red*2.55).intValue ) + Integer::toHexString( (hsbValueKitchen.green*2.55).intValue ) + Integer::toHexString( (hsbValueKitchen.blue*2.55).intValue )	
        //executeCommandLine("curl -k -X POST https://us.wio.seeed.io/v1/node/GroveLedWs2812D0/clear/3/"+hexValue+"?access_token= my Token2",5000)
        executeCommandLine("curl@@-k@@-X@@POST@@https://us.wio.seeed.io/v1/node/GroveLedWs2812D0/clear/3/FFFFFF?access_token=mytoken",5000)
        sendHttpGetRequest("https://us.wio.seeed.io/v1/node/GroveLedWs2812D0/clear/3/FFFFFF?access_token=mytoken")
        logInfo("Info", "Hexvalue: "+ hexValue)

So any idea how to get the post request to work? Finally got the hex part to work:)

Print what it returns to a log.

Remember that it is running as the openhab user which has limited permissions.

val results = executeCommandLine(<cmd>, 5000)
logInfo("Test", results)

Also see

Note, if you must do a POST, you want to use sendHttpPostRequest, not sendHttpGetRequest.

Thanks Rich, It was the reboot that was needed, not just restart of openhab…
So what is better : sendHttpPostRequest(url,timeout) or executeCommandLine(curl, timeout)

I am running openhab as root due to GPIO, and its work with the execute binding , but the hex conversion gives me the same output no matter what I do, I assume it might be due to casting. I will investigate it further, but this might be a HUE ledstrip killer. 14USD for wio link(drive up to 5 ledstrip) or 9 USD for WIO node 1 ledstrip and ws2811 ledstrip from 3usd per meter

 hexValue = Integer::toHexString( (hsbValueKitchen.red*2.55).intValue ) + Integer::toHexString( (hsbValueKitchen.green*2.55).intValue ) + Integer::toHexString( (hsbValueKitchen.blue*2.55).intValue )
ommandEvent    ] - Item 'Color_RGBKitchen' received command 102,93,100
11:59:20.163 [INFO ] [.eclipse.smarthome.model.script.Info] - Hexvalue: ff3351
11:59:20.446 [INFO ] [.eclipse.smarthome.model.script.Info] - Hexvalue: ff3351
11:59:45.280 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Color_RGBKitchen' received command 101,92,100
11:59:45.294 [INFO ] [marthome.event.ItemStateChangedEvent] - Color_RGBKitchen changed from 102,93,100 to 101,92,100
11:59:45.309 [INFO ] [.eclipse.smarthome.model.script.Info] - Redvalue: 255
11:59:45.570 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Color_RGBKitchen' received command 118,60,100
11:59:45.576 [INFO ] [marthome.event.ItemStateChangedEvent] - Color_RGBKitchen changed from 101,92,100 to 118,60,100
11:59:45.585 [INFO ] [.eclipse.smarthome.model.script.Info] - Redvalue: 255
11:59:45.863 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Color_RGBKitchen' received command 212,13,100
11:59:45.873 [INFO ] [marthome.event.ItemStateChangedEvent] - Color_RGBKitchen changed from 118,60,100 to 212,13,100
11:59:45.883 [INFO ] [.eclipse.smarthome.model.script.Info] - Redvalue: 255
11:59:46.166 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Color_RGBKitchen' received command 245,89,100
11:59:46.178 [INFO ] [marthome.event.ItemStateChangedEvent] - Color_RGBKitchen changed from 212,13,100 to 245,89,100
11:59:46.183 [INFO ] [.eclipse.smarthome.model.script.Info] - Redvalue: 255
11:59:46.433 [INFO ] [.eclipse.smarthome.model.script.Info] - Hexvalue: ff3351
11:59:46.465 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Color_RGBKitchen' received command 244,92,100
11:59:46.474 [INFO ] [marthome.event.ItemStateChangedEvent] - Color_RGBKitchen changed from 245,89,100 to 244,92,100
11:59:46.481 [INFO ] [.eclipse.smarthome.model.script.Info] - Redvalue: 255
11:59:46.703 [INFO ] [.eclipse.smarthome.model.script.Info] - Hexvalue: ff3351
11:59:46.770 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Color_RGBKitchen' received command 244,92,100
11:59:46.998 [INFO ] [.eclipse.smarthome.model.script.Info] - Hexvalue: ff3351
11:59:47.062 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Color_RGBKitchen' received command 245,95,100
11:59:47.073 [INFO ] [marthome.event.ItemStateChangedEvent] - Color_RGBKitchen changed from 244,92,100 to 245,95,100
11:59:47.079 [INFO ] [.eclipse.smarthome.model.script.Info] - Redvalue: 255
11:59:47.298 [INFO ] [.eclipse.smarthome.model.script.Info] - Hexvalue: ff3351
11:59:47.371 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Color_RGBKitchen' received command 245,95,100
11:59:47.596 [INFO ] [.eclipse.smarthome.model.script.Info] - Hexvalue: ff3351
11:59:48.192 [INFO ] [.eclipse.smarthome.model.script.Info] - Hexvalue: ff3351

It seems like the pixel are sent out wrong and that you need to clear the item all the time:

rule "Change the color in Living Room"
when
	Item MoodSelector_LivingRoom received command
then
	var String hexValue
	//red
	if (receivedCommand==1) {
		redColor = 255
		greenColor = 0
		blueColor =0
		hexValue ="00FF00"
			
	}
    //green
	if (receivedCommand==2) {
		redColor = 0
		greenColor = 255
		blueColor =0
		hexValue ="0000FF" 
	}
	//blue
	if (receivedCommand==3) {
		redColor = 0
		greenColor = 0
		blueColor =255	 
		hexValue ="FF0000" 
	}
	//white
	if (receivedCommand==4) {
		//255, 244, 229
		redColor = 255
		greenColor = 244
		blueColor =229
		hexValue ="FFFFFF" 
	}
	
	hsbValue   = HSBType::fromRGB(redColor, greenColor,blueColor)
	Color_LivingRoom.sendCommand(hsbValue.toString)
	
    executeCommandLine("curl@@-k@@-X@@POST@@https://us.wio.seeed.io/v1/node/GroveLedWs2812D0/clear/60/000000?access_token=mytoken",5000)
    executeCommandLine("curl@@-k@@-X@@POST@@https://us.wio.seeed.io/v1/node/GroveLedWs2812D0/clear/60/"+hexValue+"?access_token=mytoken",5000)
end

I think it is largely personal prefrence. Personally I would use the sendHttpPostRequest. It is more self contained with fewer external dependencies or troubles dealing with permission problems and the like.

I’m probably not going to be much help with the HSB stuff. I’ve not used it and it is hard to analyze the code on my phone. If it is still a problem in a couple of weeks I’ll have a look again.