PLEG: Confirm that eq returns String Contains

I have been working on a Water Saver that works like this:

is it raining?

Trigger: IsRain (checks to see if the word ‘Rain’ is in the Conditions of Weather Underground Plugin)

it just rained a lot…

Condition: LottaRain = IsRain AND IsRain>30:00
Action: Turn On Water Saver Virtual Switch

it hasn’t rained a lot today…

Condition: DriedUp = !LottaRain AND !LottaRain>24:00:00
Action: Turn Off Water Saver Virtual Switch

This depends on the ‘eq’ string function returning TRUE if the Weather Condition string contains ‘Rain’ as WU publishes Light Rain, Heavy Rain, etc…

but it doesn’t seem to be that way… it is looking for an exact match.

I clipped a piece of PLEG basics for reference, looking for help to return TRUE if a string contains…

I would expect ‘eq’ to be an exact match. Perhaps Richard can add in a “contains” operator (They have this in one of the languages I write in: ColdFusion). All he has to do is an indexOf and see if it is greater than -1 (I don’t know if Luup has a comparative function to indexOf or not)

*The above is based on my experience as a programmer, but I have not delved at all into LUUP or LUA so I have know idea what is actually possible or not. It’s just a suggestion.

I see the word contains means different things to different people…

PLEG’s eq operator looks for an exact match between the two string terms. It doesn’t have a string operator for includes. Maybe RTS will add one at some point.

Meanwhile, you could add a periodic scene to read the WUG variable and set a VirtualSwitch if rain is mentioned. Something like:

local wID = 13 -- Device ID of WUG local dID = 99 -- Device ID of Rain VirtualSwitch local condition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","Condition",wID) local rain = "0" if string.find(string.lower(condition),"rain") ~= nil then rain = "1" end local status = luup.variable_get("urn:upnp-org:serviceId:VSwitch1", "Status", dID) if status ~= rain then luup.call_action("urn:upnp-org:serviceId:VSwitch1", "SetTarget", {newTargetValue = rain}, dID) end

that works. I am already pulling the WU info from an instance running on another Vera and depositing in a local variable container. So, I can just modify the scene that is doing that already.

I can also easily add the ‘Drizzle’ and ‘Thunderstorm’ conditions to the mix.

Thanks so much.

closing the loop

Actual Condition deposited in Variable2.

Logical Condition results from Lua code deposited in Variable1