Hi,
I need some help with one of the rules.
I’m trying to convert string to number, but I’m lacking skills.
Topic grew out from here, but I think it’s more proper to open new one under rules category:
https://community.openhab.org/t/http-table-value-pulling-and-conversion-with-rules/68356
items:
String Electricity_price "Electricity_price [%s]" {http="<[https://www.nordpoolgroup.com/api/marketdata/page/47?currency=EUR&endDate={}:60000:JSONPATH($.data.Rows[0].Columns[0].Value)]" }
Number Electricity_price2 "Electricity_price2 [%.2f]"
Switch Renew_price "Renew_price"
rules:
var Number conversion
var String get_Electricity_price
rule "conversion"
when
Item Renew_price changed
//Item Electricity_price changed //or
// System started //or
//Item Electricity_price2 == NULL //gives error
then
get_Electricity_price = Electricity_price.state.toString();
//conversion = Integer.valueOf(get_Electricity_price);
conversion = Double.parseDouble(get_Electricity_price);
Electricity_price2.postUpdate(conversion);
end
about triggering conditions:
As input data is updated only once per day, I created a switch to run the rule (while testing).
Ideally I would like to run the rule on startup and when value changes.
about script block:
I get error for conversion.
log:
2019-02-27 22:09:13.098 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'conversion.rules'
2019-02-27 22:09:34.850 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'conversion': For input string: "34,05"
Please share ideas. Thanks