Thanks rich, i was testing a lot of JSONPATH constellations (trial & error) in the group item but without success…
i did try your guess too, no luck - so i decided to go with different rules - this works as expected
just one little thing, i get a string out of my rule and want to have it as DecimalType for rounding - could you help here ?
i found your post in another thread about String:format, but dont get it to work correctly…
Thanks!
my guess was:
rule "BITCON EUR (coinmarketcap)"
when
Time cron "0 * * * * ?"
then
var String json = sendHttpGetRequest("https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=EUR")
var String value = transform("JSONPATH", "$.[0].price_eur", json)
val value = String::format("%.1f EURO", (Bitcoin_EUR_JSON.state as DecimalType).floatValue
logInfo("JSON RULE","*************: " + value + " EURO" )
Bitcoin_EUR_JSON.postUpdate(value)
end
[ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'BITCON EUR (coinmarketcap)': Could not cast 14704.9216524 to org.eclipse.smarthome.core.library.types.DecimalType; line 26, column 50, length 37
rule "BITCON EUR (coinmarketcap)"
when
Time cron "0 * * * * ?"
then
var String json = sendHttpGetRequest("https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=EUR")
var String value = transform("JSONPATH", "$.[0].price_eur", json)
value = String::format("%.1f EUR", Float.parseFloat(value))
logInfo("JSON RULE","*************: " + value + " EURO" )
Bitcoin_EUR_JSON.postUpdate(value)
end
EDIT:
i found a solution for a Number Item finally
rule "BITCON EUR (coinmarketcap) Test"
when
Time cron "0 * * * * ?"
then
var String json = sendHttpGetRequest("https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=EUR")
var String value = transform("JSONPATH", "$.[0].price_eur", json)
value = String::format("%.0f", Float.parseFloat(value))
logInfo("JSON RULE","******BITCOIN-TEST*******: " + value )
Bitcoin_EUR_JSON_Test.postUpdate(Float::parseFloat(String::format("%s",value)))
end
Thanks for this great info. It seems to work very nicely. I still have another problem/question. I would also like to add the value of other currencies. For many of them the value is lower then or around 1. Therefore it is important to also have the decimal values. Your rule works till “logInfo(“JSON RULE”,"BITCOIN-TEST*: " + value )” and the variable “value” will show the right value, but the transformation of it into a “Number” does not seem to work.
Any idea how I could solve this?
Big thank you !
Tijl
jwiseman
(Mr. Wiseman (OH 4.2 Snapshot on Pi4))
11
Hi Philipp,
Can you post what is in the transform file for JSONPATH to this thread?
Best, Jay
jwiseman
(Mr. Wiseman (OH 4.2 Snapshot on Pi4))
12
Sorry, you can ignore. I didn’t have the BINDING installed.