How to convert a string to a number with Xpath

Hey Guys,

I created a counter with python for Raspberry Pi. The values will be saved in an XML file. With XPath I’m “extracting” the value in a string item. Now I’m struggling with converting the counter in a number item.

I’m using this rule therefore. It’s the rule from openhab doc.

rule "Convert XML to Item Type Number"
  when
    Item Temperature_xml changed
  then
    // use the transformation service to retrieve the value
    // Simple
    val mytest = transform("XPATH", "/*[name()='PTZStatus']
                                     /*[name()='AbsoluteHigh']
                                     /*[name()='azimuth']
                                     /text()", 
                                    Temperature_xml.state.toString )  
    // post the new value to the Number Item
    Temperature.postUpdate( newValue )
end

But I don’t know how to update the temperature item with postUpdate(newValue). It looks like it doesn’t work.
Someone an idea?

Thanks!

Why do you say this?

What do the logs say?

No error in the logs.
But number item is still empty and gives „NULL“ as feedback.

Add logs to see what the XPath is returning.

All transformations always return a string. However, if the XPath is returning a String that can be parsed into a number, you can update a Number Item with with it and it will work. If it’s not parsable, you’ll get an error in the logs.

Are you even certain this rule is running at all?

I’ve checked the logging and I got following error:

2022-12-20 22:18:31.534 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'gas-1' failed: The name 'newValue' cannot be resolved to an item or type; line 17, column 25, length 8 in gas

The rule only has two lines. You create mytest and then try to use newValue which doesn’t exist, as the error tells you.

Hey Guys,

I checked my logs and I found the following error:

2022-12-23 20:38:35.021 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'gas-1' failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.BusEvent.postUpdate(org.openhab.core.items.Item,java.lang.String) on instance: null in gas

Somebody an idea what it means?

Thanks!

Assuming the same rule as above, what ever mytest is, it’s not something that can be parsed into a number or a number with units.

It sure would be convenient if there were a way to see what mytest is.