HTTP POST Request help needed

Hi! I try send notifications to LaMetric Time (I know about binding, but it did not provide icons in notifications)
Here is curl command:

curl -X POST -u "dev:xxxx" -H "Content-Type: application/json" -d " { \"model\": { \"frames\": [ { \"icon\":\"a2867\", \"text\":\"Hello\"} ] } }"

I try and no luck:

executeCommandLine(Duration.ofSeconds(6), "/bin/sh", "-c", "'curl -X POST -u \"dev:xxxx\" -H \"Content-Type:application/json\" -d \"{\"model\":{\"frames\":[{\"icon\":\"a2867\",\"text\":\"Hello\"}]}}\"'")

executeCommandLine(Duration.ofSeconds(6), ("curl -X POST -u 'dev:xxxxx' -H 'Content-Type:application/json' -d '{\"model\":{\"frames\":[{\"icon\":\"a2867\",\"text\":\"Hello\"}]}}'").split(" "))

Read DOCs, and not found how to send -u parameter from curl in openHAB sendHttpPostRequest HTTP Actions

Why don‘t use sendHttpPostRequest?

I just checked my code and I don‘t use -u at all

Need to provide user and pass in request

-u "dev:xxxx"

I dont know how

sendHttpPostRequest(String url, String contentType, String content, Map<String, String> headers, int timeout)

Where to put -u?

You can try the code below - just change your ApiKey, ip-address and the json-data:

val String LaMetric_ApiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
val String LaMetric_Notification_Endpoint = "http://dev:" + LaMetric_ApiKey + "@"
val String LaMetric_Notification_Headers = "application/json"
var String LaMetric_Data = "{your json here}"
var String API_RETURN = sendHttpPostRequest(LaMetric_Notification_Endpoint,LaMetric_Notification_Headers,LaMetric_Data,20000)

Yes! Thank you @Flip :grinning:

Is it working?


Well done :slight_smile: Maybe you can mark the code above as solution - just in case somebody else is having this problem

Did it already :slightly_smiling_face:

1 Like

I’m struggling using this “My Data (DIY)” App for the Lametric Time with OpenHAB 3.
Link to the documentation: My Data (DIY) App on LaMetric Market | LaMetric Time clock for smart home

I’m lost what " 1. Expose your data to some URL available in the same local network with the device in predefined JSON format (more about that below)." actually means.
How to achieve this? Do i need to use the HTTP binding for that?
What URL do i have to use? Help is really appreciated!

You need to create file /etc/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NDEtNzIzYy1mMzQ2LWI4ZDgtMzA0OTRlODgzY2E5IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjk3ZjBmZTE4LTBlYzQtODc0OS05MzYzLWQ3MzE4ODUyMjY1MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PgH//v38+/r5+Pf29fTz8vHw7+7t7Ovq6ejn5uXk4+Lh4N/e3dzb2tnY19bV1NPS0dDPzs3My8rJyMfGxcTDwsHAv769vLu6ubi3trW0s7KxsK+urayrqqmop6alpKOioaCfnp2cm5qZmJeWlZSTkpGQj46NjIuKiYiHhoWEg4KBgH9+fXx7enl4d3Z1dHNycXBvbm1sa2ppaGdmZWRjYmFgX15dXFtaWVhXVlVUU1JRUE9OTUxLSklIR0ZFRENCQUA/Pj08Ozo5ODc2NTQzMjEwLy4tLCsqKSgnJiUkIyIhIB8eHRwbGhkYFxYVFBMSERAPDg0MCwoJCAcGBQQDAgEAACH5BAUUAAMALAAAAAAIAAgAAAIT3GRhyzchhFInomUvgnKA1mhGAQAh+QQFFAADACwAAAAACAAIAAACCpwNpxc76aKcbBUAIfkEBRQAAwAsAAAAAAgACAAAAgrcYqkq6w9ZVMAUACH5BAUUAAMALAAAAAAGAAgAAAIK3GRhy+2sXkOmAAA7"
//other base64 icons

rule "LaMetriс"
when Time cron "*/15 * * * * ?" //run every 15 seconds
//some your code
iconBase64 = clear
textOutTemp = YOURTEMP.replaceAll(".0°","°")

    executeCommandLine(Duration.ofSeconds(6), "/bin/sh", "-c",
    "(echo '
    \"frames\": [
            \"text\": \"" + textOutTemp + "\",
            \"icon\": \"data:image/gif;base64," + iconBase64 + "\"
	' > /etc/openhab/html/lametric.json) >/dev/null 2>&1; echo $?")

I really appreciate writing a possible solution to my problem!
But sadly i didn’t get any point of the solution. :frowning:

What about the HTTP binding and the configuration of the thing? Do i need a Channel in this Thing?
How to fill the field of the “Basis-URL”?

I was expecting that i have to do something in the area of this:

rule "Update My Data DIY"
        Item PostHTTP received command ON
        val String URL = ""
        var String contenttype = "application/json"
        var String jsondata = '{"frames" : [ {"icon": "794","text": "Hello!"}]}'

        logInfo("Update My Data DIY", "Sending Command" + jsondata + "data end")

        sendHttpPostRequest(URL, contenttype, jsondata)