Sensor update from Lua code

Hi there,

I’m using reactor to control a RS485 bathtub controller. I’m using this code in the RunLua:

local enter = string.char(0x0d, 0x0a);
local commandtosend = “HIDRO1:1;HIDRO1:1;” … enter;
local socket = require(“socket”);
local ADDRESS = “192.168.0.251”
local PORT = “23”
c = assert(socket.connect(ADDRESS, PORT))
c:settimeout(2)
print("Sending Command:: " … commandtosend)
local sres, serr = c:send(commandtosend)
local data, rerr = c:receive(5)
c:close()

It’s working OK so far. But…
If i send HIDRO1:?; as the command, it would return me 0 or 1 reporting if it’s off or on. Is there a way to query this value from the controller and, using the feedback, update the sensor status?

There’s an HTTP request action that can capture the response.

Docs: https://www.toggledbits.com/static/reactor/docs/HTTP-Request-Action/

hi rigpapa,

it’s not http actually. the control i’m using, as posted, is a telnet command. The device doesn’t have a built-in http server, only a telnet interface (passwordless), as it acts as a bridge for a RS485 controller.

Create an expression/variable with no expression on the “Expressions” tab. Then add to your Lua:

luup.call_action( "urn:toggledbits-com:serviceId:ReactorSensor", "SetVariable",
    { VariableName="your-variable-name", NewValue=data }, Reactor.id )

You can then write a condition to check the variable value and react accordingly.

Best Home Automation shopping experience. Shop at getvera!

© 2020 Vera Control Ltd., All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules