Jump to content
C4 Forums | Control4

Programming question: substring comparison


MikeK

Recommended Posts

Greetings,

I have a driver that has a string variable that I would like to attach some programming to, but I can't do a simple equality comparison. I need to see whether the string contains a particular string.

Specifically, this is a lock, and I want to change behavior depending on how the lock is locked. The lock writes a message into this string variable that says how it was locked. The first part of the message is exactly what I want, but unfortunately the lock driver appends a date and time, which is not relevant and will prevent direct comparison. Here's an example: "Locked Manually - Wed Aug 16 10:50:35 2023"

The part I care about is "Locked Manually".

The basic conditional programming in Composer just has "is =" and "is !=". I'm wondering if there's a way to do more advanced string comparison. Perhaps somebody has written a little utility driver? Or maybe there's something obvious that I'm missing. I saw that ChowMain has a driver for doing variable manipulations, but unfortunately it doesn't seem that this sort of string comparison is supported in that one.

Thanks!

Link to comment
Share on other sites


I'm also curious about string comparison / manipulation, but perhaps you can program off the underlying lock/unlock events and pop the results into a variable that you can use to drive your logic later (or real-time, depending on what you're trying to do)?   See screen shot showing events available from August lock as an example.

 

Screenshot 2023-08-16 at 1.34.48 PM.png

Link to comment
Share on other sites

25 minutes ago, cnicholson said:

perhaps you can program off the underlying lock/unlock events

Thanks for your reply! Unfortunately, there doesn't seem to be a way to use the events from the driver I'm using to get what I want. On this driver (which is for the Baldwin Zigbee lock that Control4 used to re-sell), there are two lock events: "Locked" and "Locked Manually". Locked fires whenever the lock is locked using the motor. So this means that it is triggered if you press the button on the exterior keypad, or if you send it a command by ZigBee. Locked Manually fires if you lock the lock with the knob or the key. I want to have programming run only when the lock is locked from the exterior keypad (because that means that I'm leaving the house and I want to have lights and TVs turn off, etc.)

There's a newer version of the lock driver that has a "Locked Proxy" event like the one you've shown for the August. That means that it was locked by programming. Unfortunately, that driver treats the keypad locking and the knob/key locking equivalently. They're both called "Locked Manually". So, both versions of the driver combine "locked with the keypad" with one of the other methods, making it impossible to use the events to distinguish.

What I discovered, though, is that the status message that the older driver puts into that variable is unique for proxy, keypad, and knob/key, so if I can just parse that string, I can fully distinguish. But since it tacks the stupid date/time on there, I can't use a string comparison. 

Link to comment
Share on other sites

Ah! I just discovered that the newer driver for this lock (the one with the Locked Proxy event) has a similar status variable, but it does not tack the date/time onto the end. It seems to provide distinct messages for all three lock events:

  • Manually Locked
  • Keypad Locked by Keypad
  • Command Locked

This may be good enough. I'm still interested to know if there's a way to compare against a substring, though, because it would save me a little work to not have to replace the drivers for each of these locks.

Link to comment
Share on other sites

Yeah, thanks, that's the one I mentioned earlier. As far as I can tell from its documentation, it will let you assemble strings by formatting the contents of other variables, but it doesn't have an ability to truncate or compare a substring.

Link to comment
Share on other sites

11 minutes ago, MikeK said:

Yeah, thanks, that's the one I mentioned earlier. As far as I can tell from its documentation, it will let you assemble strings by formatting the contents of other variables, but it doesn't have an ability to truncate or compare a substring.

This is correct. It will not do what you want.

Link to comment
Share on other sites

26 minutes ago, zaphod said:

Is there any way in drivers to call underlying Lua code?  Could you use substring functions from Lua in any way?  Like how in Python you can do a shell command with the os.system() function.

That would be excellent. I haven't found a way to do that but perhaps someone knows?

Link to comment
Share on other sites

29 minutes ago, zaphod said:

Is there any way in drivers to call underlying Lua code?  Could you use substring functions from Lua in any way?  Like how in Python you can do a shell command with the os.system() function.

@alanchow Is there any way this could be done?  Or could you add string function capability to your variable manipulator driver?

Link to comment
Share on other sites

I’m pretty sure that the Yatun variable manipulator driver (edit: called their calculator driver) allows for some basic string manipulation.  However, I am not quite sure where one can get this driver now that Yatun have stoped supporting their C4 drivers.  It may still be available on their website.  I understand that HopSoft took over support of some of their drivers so they may also have this (although I don’t recall seeing such a driver by HopSoft).

Edited by South Africa C4 user
Link to comment
Share on other sites

17 minutes ago, South Africa C4 user said:

I’m pretty sure that the Yatun variable manipulator driver allows for some basic string manipulation.  However, I am not quite sure where one can get this driver now that Yatun have stoped supporting their C4 drivers.  It may still be available on their website.  I understand that HopSoft took over support of some of their drivers so they may also have this (although I don’t recall seeing such a driver by HopSoft).

https://www.yatundev.eu:44300/drivers/

Try this… it claims to support all standard Lua string commands.  I have used it quite a lot in programming (but not for strings in the last few years so I am a bit hazy on what all it can do). I am 99% sure that I used it for exactly what you are trying to do (essentially a left string function).

Edited by South Africa C4 user
Link to comment
Share on other sites

Ah! Thanks, I had seen mention of that, but Yatun has a message on their site saying that they no longer support drivers, and that they had sold off the popular ones. I wasn't able to find that one before. Seems to require a login to download it. I will see if I can get it, though!

Link to comment
Share on other sites

11 hours ago, MikeK said:

Ah! Thanks, I had seen mention of that, but Yatun has a message on their site saying that they no longer support drivers, and that they had sold off the popular ones. I wasn't able to find that one before. Seems to require a login to download it. I will see if I can get it, though!

It’s a free driver.  If you struggle, I can probably get a copy to you.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.