openhab / openhab-core

Core framework of openHAB
https://www.openhab.org/
Eclipse Public License 2.0
925 stars 425 forks source link

Image Item returns raw type instead of actual image #2452

Closed jti989 closed 3 years ago

jti989 commented 3 years ago

I have a rule sending out a message to my Gotify server using sendHttpPostRequest(). Sending text messages works fine.

When I try to send an image I have to use a workaround. This is my rule:

rule "temprule"
    when
       Time cron "0,30 * * ? * * *"
    then
       var response = sendHttpGetRequest("http://openhab3:8080/rest/items/ZM_Monitor1_Image/state")
    //    response = ZM_Monitor1_Image.state.toString
       sendHttpPostRequest("http://gotify/message", "application/json","{  \"message\": \"![Image](" + response + ")\",  \"priority\": 5,  \"title\": \"Bewässerung\", \"extras\": {\"client::display\": {\"contentType\": \"text/markdown\" }}}",  headers, 3000)
    end

If I try to use the Item directly (commented out in my example) I get the message "![Image](raw type (image/jpeg): 101034 bytes)". If I use the workaround to get the item state over HTTP the process works fine and the image is delivered as it should.

It does not matter if I use .toString for the item or not.

Am I stupid here? What am I doing wrong?

lolodomo commented 3 years ago

The image data is returned by the method toFullString, not toString. To be checked if this method is available in the DSL rule engine.

jti989 commented 3 years ago

This is indeed working, thank you!

response = ZM_Monitor1_Image.state.toFullString