Lua text sensor trim devicechange text to last digits Topic is solved

Moderator: leecollings

Post Reply
daemonshome
Posts: 19
Joined: Saturday 30 May 2020 15:30
Target OS: -
Domoticz version:
Contact:

Lua text sensor trim devicechange text to last digits

Post 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?
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua text sensor trim devicechange text to last digits

Post by jvdz »

Something like this?: (untested)

Code: Select all

if (devicechanged[sensorLogRF]:sub(-8) == "10000001") then 
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
daemonshome
Posts: 19
Joined: Saturday 30 May 2020 15:30
Target OS: -
Domoticz version:
Contact:

Re: Lua text sensor trim devicechange text to last digits

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lua text sensor trim devicechange text to last digits

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest