i have a Govee H6199 tv backlight strip and trying to incorporate into my openhab just to turn on and off,I have found this Govee api ,i got an api key allright and i guess i have to use this example
i came up with this rule based on my limited knowledge
rule "govee"
when
Item test changed
then
val url = "https://developer-api.govee.com/v1/devices/control"
var String header = "Govee-API-Key: 0af6b18b-0303-4c87-b68a-17xxxxxxxxx"
var String body = '{"device": "34:20:03:B6:xx:xx", "model": "H6199", "cmd": {"name": "turn","value": "on"}}'
sendHttpPutRequest(url, header, "application/json", body)
end
but i get an error
2021-06-18 10:14:21.152 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'govee': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.HTTP.sendHttpPutRequest(java.lang.String,java.lang.String,java.lang.String,int) on instance: null
For some reason, you’ve decided to give your parameters in a different order from the document, so it’s probably struggling to work what is which. sendHttpPutRequest(url, contentType, content, headers, timeout)
Headers is special, headers is a Map type object, like a list or array, because it usually has multiple elements.
That’s why the example I showed you uses
When you are experimenting with this, it’s useful to get any response message. You need to give a timeout to collect that.
Sure. Don’t see why that would be any easier than a five-line rule, but just find out how to make HTTP requests in whatever scripting language you want to use. Remember you want to pass an on/off selection somehow.
I realise now I gave a poor example of ‘headers’ scripting - that was in javascript, not the DSL language you’re currently using.
Looking for a DSL example led me to this …
The upshot seems to be that headers are not supported in OH2 actions, and mention of them snuck into OH2 docs in error.
I don’t think this is going to work this way. You may be forced to use an external script after all (probably a bash script using curl).
use the extended syntax var RET = executeCommandLine("/etc/openhab2/scripts/govee.sh", 2000)
to get output returned. You may have to redirect the output from your curl command.
Alternatively you can redirect the output of the curl command to a temp. file within your shell script.
You might be doing to same thing I did. For device name, even though it says its the mac address, its not. Do a GET on https://developer-api.govee.com/v1/devices with your api key header to find the actual address