How do we increment an item value from within a widget?

I have a simple widget and I want the value to increment by a set amount.

- component: oh-button
                        config:
                          iconF7: arrowtriangle_down
                          iconSize: 30
                          color: blue
                          action: command
                          actionCommand: props.itemsetpoin-0.5
                          actionFeedback: Temperature Reduced
                          actionItem: =props.itemsetpoint

I’m not sure how to increment with the actionCommand:

Thanks
Rexz

It seems that when we reference any item, it always comes back as type string, so I can’t perform any addition or subtraction otherwise I get the error:

No message body reader has been found for class java.lang.String, ContentType: application/octet-stream

I tried to access the current value via the props and by items.itemname.state.

I have not tried this, neither do I know if this is possible. However, it looks like you have a typo here. I think itemsetpoin should be itemsetpoint

Thanks for that. Yeah it was a typo but only because I was testing so many things… unfortunately it isn’t the fix. I’ve seen other examples of using functions like math.round() on states in the yaml works, but I’ve no idea how to convert the string to a float in order to do simple addition/subtraction.

The magic word for this action is parse, probably parseFloat("somestring")?

Well I haven’t tried just throwing a parse in there but didn’t know if we had access to that in the yaml.

I have decided for now that I will need to create some rule to increment or decrement and then either call that from the widget or change a string item and let a rule watch for changes :confused:

Ok for anyone stuck on any similar issues I was able to use =Number.parseFloat(). I was originally just using parseFloat() which obviously didn’t work.

Thanks
Rexz

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.