Page 1 of 1

Lua text sensor trim devicechange text to last digits

Posted: Sunday 10 January 2021 8:06
by daemonshome
Hi all,
With arduino I am sending in to domoticz some data to TEXT sensor.
I am using the following code to trigger if text sensor has some changes. ( rewriting the code now )

Code: Select all

 if (devicechanged[sensorLogRF] == "[22:51:48] 610ecc_10000001") then
		if (otherdevices['Switch'] == 'Off') then
	        commandArray[getdevname4idx(4)] = "On"
	    end
	    if (otherdevices['Switch'] == 'On') then
	        commandArray[getdevname4idx(4)] = "Off"
	    end
	    print("Rem1")
	end	
I need just a piece of that information, lets say the last x digits. = 10000001
Any ideas how to trim the sensorLogRF device ?

Code: Select all

 if (devicechanged[sensorLogRF] == "*10000001") then
asterisk, wildcard - would be a perfect solution...but thats not working here.
Any idas to try?

Re: Lua text sensor trim devicechange text to last digits

Posted: Sunday 10 January 2021 10:04
by jvdz
Something like this?: (untested)

Code: Select all

if (devicechanged[sensorLogRF]:sub(-8) == "10000001") then 
Jos

Re: Lua text sensor trim devicechange text to last digits

Posted: Tuesday 12 January 2021 7:49
by daemonshome
no, the idea above does not work properly.
However I have figured out, if some are interested.

code part below

Code: Select all

if (devicechanged[sensorLogRF]) then
    --print(sensorLogRF.." devchanged: "..otherdevices_svalues[sensorLogRF])
    inc_raw_text = otherdevices_svalues[sensorLogRF]
    inc_text = string.sub(inc_raw_text, 1, 17)	
    --I need the first 17 characters to compare
    print(sensorLogRF.."trim_DEV-RF: "..inc_text)
    
    if (inc_text == "[123456]_12345678") then
		print(sensorLogRF.."code received")
    end

Re: Lua text sensor trim devicechange text to last digits

Posted: Tuesday 12 January 2021 8:40
by waaren
daemonshome wrote: Tuesday 12 January 2021 7:49 no, the idea above does not work properly.
The answer @jvdz gave on your original question
I need just a piece of that information, lets say the last x digits. = 10000001
Was perfectly OK. If you change the question you should not be surprised that the answer must be different to.