Luaxp expression

I’m trying to store&manipulate SiteSensor’s results in Reactor expressions/variables and essentially trying the following code:

local result = getstate( 310,"urn:toggledbits-com:serviceId:SiteSensor1", "FailedSince" ) 
if (result == nil) then    
  -- nothing 
else    
  strftime("%X %x", result) 
end

I might be obvious why this fails, but what would be the best way to achieve this in Reactor?

Note:

  1. LuaXP expressions are not Lua.
  2. Take a look at the if() function. That’s one of two quick ways to do what your code does in one step/expression.

Reference:

thanks again, used solution below:

if ( getstate( 310,"urn:toggledbits-com:serviceId:SiteSensor1", "FailedSince" ) != nil, strftime("%X %x", getstate( 310,"urn:toggledbits-com:serviceId:SiteSensor1", "FailedSince" ) ) )
1 Like