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?
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.
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
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