device.updateSetting not updating device preferences

So as a disclosure here, I basically was programming this blind last night since I can't seem to find any documentation on what calls I can actually make with a hubitat driver (I only stumbled across device.updateSetting after poking around some sample code on the hubitat github hxxps://github.com/hubitat/HubitatPublic/blob/master/examples/drivers/GenericZigbeeRGBWBulb.groovy) and more importantly, I have not programmed anything in forever, much less in a language I never heard of till HE (Groovy)

So my top question is simply: Where do I find a full list of existing functions within hubitat that I can call with my driver?

My next question is more complex, I have an existing driver for my GE Z-Wave Plus Motion Switch that lets me set the occupation mode as a preference, however I want my rule engine to set occupation mode by time of day (but I can't edit preferences via RE, I need to make a command apparently)

So I make my command:

metadata {
	definition (name: "GE Z-Wave Plus Motion Switch", namespace: "Botched1", author: "Jason Bottjen") {
        command "Vacancy"
	}

preferences {
	 input "paramOperationMode", "enum", title: "Operating Mode", description: "Occupancy: Automatically turn on and off the light with motion\nVacancy: Manually turn on, automatically turn off light with no motion.", options: ["1" : "Manual", "2" : "Vacancy", "3" : "Occupancy (default)"], required: false, displayDuringSetup: true
    }

def Vacancy() {
    if (logEnable) log.debug("Vacancy")
    def cmds = []
    cmds << zwave.configurationV2.configurationSet(scaledConfigurationValue:  paramOperationMode.toInteger(), parameterNumber: 3, size: 1).format()
    cmds << zwave.configurationV2.configurationGet(parameterNumber: 3).format()
	delayBetween(cmds,1000)   
}

This works exactly as expected, however the driver has functionality to verify the device has the right settings, and if I left my function as-is every 3000 seconds it would override the setting I chose. so I want to update the device preferences so I try to add a line to my function to do just that:

    device.updateSetting("paramOperationMode",[value:"\"2\" : \"Vacancy\"", type:"text"])

Now, I have tried many things here to match the preferences " input "paramOperationMode", "enum" with no success. I have tried values of 2, Vacancy, the above combined, types of text (based off a forum thread I cant find now) and type enum.
Currently this will clear whatever setting is in the update setting field as it defaults to the "Click to set" after I execute, which implies some form of success, but I can't seem to take that last step to actually have to set to the vacancy setting.

Any help is appreciated.

Also I apologize, I don't see how to edit a post, I trimmed down my vacancy function a bit too much, it should also have the var paramOperationMode which I set to 2, but using 2 in the configurationSet would accomplish the same thing. So I promise that "paramOperationMode.toInteger()" is not undefined in this context.

device.updateSetting("debugOutput",[value:"false",type:"bool"])

Hubitat is very similar to SmartThings. A LOT of the documentation there applies. The remaining can be found: Developer Documentation - Hubitat Documentation

https://docs.smartthings.com/en/latest/getting-started/first-smartapp.html

1 Like

Thanks for your reply. Looking at the developer documentation, I see the functions for:
void updateSetting(String name, Map options)
void updateSetting(String name, Long value)
void updateSetting(String name, Boolean value)
void updateSetting(String name, String value)
void updateSetting(String name, Double value)
void updateSetting(String name, Date value)
void updateSetting(String name, List value)

But nothing for enums, does that imply the functionality is not supported, or do enums have some sort of inheritance based on their defined typing? (in this case "1" "2" and "3") IF thats the case, I have tried:
device.updateSetting("paramOperationMode",[value:2, type:"enum"])
device.updateSetting("paramOperationMode",[value:2, type:"long"])

etc. Do I need to refactor the preferences to be a supported type or am I missing something obvious?

You should not have to do that, if you are setting the value correctly from the driver edit page and saveing your changes then it should update the device. If you aren't clicking save, then that would be a problem.
But assuming you are clicking save, you are saying the setting you are applying is not "taking"? I would think that would be better solved the original developer of the driver. @JasonJoel, this is your driver for the GE Z-wave motion switch, correct? Maybe you could help @niff441 out with what he is seeing with this driver.

I think he may be referring to the ST driver that supported those commands. But I could be wrong. The ST one was the starting point for my 1st version, until I rewrote the whole thing.

That said, I have a Hubitat version (somewhere) that supported all of the ST custom driver occupancy/vacancy modes. I think they all worked, but I ripped that out of my driver a year ago...so it's hard to remember.

I'll look this weekend when I have time. For all I remember it may be on my GitHub still as a real early version.

Well, mystery solved even if I don't quite understand groovy yet. One last run of code tests where I followed csteele's advice and put the value in quotes, even if it is a number, got me the right answer:

device.updateSetting("paramOperationMode",[value:"2", type:"enum"])

Although if anyone can explain why paramOperationMode.toInteger() and "2" don't match (given if (logEnable) log.debug(settings.paramOperationMode) returned 2 I would be interested.

Finally, I do apologize for all these rapid-fire posts, but I really see no way to edit existing posts, am I missing some obvious functionality?

Also for prosperity if anyone wishes to do what I'm doing for this driver, here are the 3 functions:

def Occupancy() {
    if (logEnable) log.debug("Occupancy")
    paramOperationMode = 3
    def cmds = []
    cmds << zwave.configurationV2.configurationSet(scaledConfigurationValue:  paramOperationMode.toInteger(), parameterNumber: 3, size: 1).format()
    cmds << zwave.configurationV2.configurationGet(parameterNumber: 3).format()
	delayBetween(cmds,1000)
    device.updateSetting("paramOperationMode",[value:"3", type:"enum"])
}

def Vacancy() {
    if (logEnable) log.debug("Vacancy")
    paramOperationMode = 2
    def cmds = []
    cmds << zwave.configurationV2.configurationSet(scaledConfigurationValue:  paramOperationMode.toInteger(), parameterNumber: 3, size: 1).format()
    cmds << zwave.configurationV2.configurationGet(parameterNumber: 3).format()
	delayBetween(cmds,1000)
    device.updateSetting("paramOperationMode",[value:"2", type:"enum"])
    //if (logEnable) log.debug(settings.paramOperationMode)
}

def Manual() {
    if (logEnable) log.debug("Manual")
    paramOperationMode = 1
    def cmds = []
    cmds << zwave.configurationV2.configurationSet(scaledConfigurationValue:  paramOperationMode.toInteger(), parameterNumber: 3, size: 1).format()
    cmds << zwave.configurationV2.configurationGet(parameterNumber: 3).format()
	delayBetween(cmds,1000)
    device.updateSetting("paramOperationMode",[value:"1", type:"enum"])
}

PS: @Ryan780, thanks for your reply, I just saw your post while I was typing; When you say driver edit page I am not sure what you are referring to, could you elaborate?
My use case for the above code snippets is that although the preferences section of my device allows me to change the mode, to the best of my research and knowledge, rule machine does not allow settings to be called/acted upon as actions. This caused me to create commands that could be invoked as follows:
(apparently I can paste an image but am not allowed to post it)
Select Trigger Events:
Mode becomes Day------------>Select Actions to Run: Vacancy() on Bedroom test motion
This now sets the occupancy mode, and updates the preferences on the device page.
If there is a better way to do this I am incredibly interested (I'm not great at this coding thing)!

It's the Device Edit page, not the driver edit page. That is the main page where you can set the settings for the device. When you click on the device in the big list. If you are setting the setting there it should take and you shouldn't have to recall a function. I suspect that this is happening because you are not actually making the setting change on the device itself. So, when the driver recalls the setting from the device it is overwriting what you had in the driver. Can you show a screenshot of the device's page?

Is this what you are looking for? Manual Occupancy and Vacancy are the 3 commands I created referenced above.
>Sorry, you can't put images in a post
hxxps://i.imgur.com/ziSCIJM.png

You should not need to create those commands is my whole point. After you changed the setting to the one you wanted, did you click "save'?

Yes, that aspect of the driver works perfectly, however from rule engine, I don't know of a way to set preferences by rule event.
hxxps://i.imgur.com/OhNlPex.png
If I have the device set as "manual" prior to this and want "Vacancy" is there a way in Rule Machine to edit preferences? The only way I found was to make a command and call the command. However, the driver checks the config of the switch every 3000 seconds, so if I did not update the preference with the running of the command to change it to Vacancy, it would end up overwriting vacancy with the last selected preference setting.

Right. He wants to change those settings programmatically from RM, so he does need commands to do so. So it makes sense that he added those commands to the driver.

I stripped those commands out of my driver, because I just leave the switches in manual mode, and handle all of the on-off behavior in motion lighting in the hub.

That was my first plan, but the responsiveness of not querying the hub for logic based on events from the motion sensor was enticing... At least before I spent all this time making the functionality work. :laughing:

You should have asked... Like I said in the other thread (?) I have a version of the driver that has those commands in it already working. I'm sure I could find it / dig it up.

Moot point now I guess since yours is working already though.

Indeed, I appreciate the offer, it was a worthwhile exercise at least. And while I have you hear at least let me say thanks for creating said driver, I am a huge fan of FOSS, and the fact I was able to find your code and make the changes I needed for my use case speaks volumes to this platform and the community here (even more so that you replied after someone tagged you in this thread)

1 Like

Well, one the left is an integer and the right is a string.
Preference values and keys will always be returned as strings even if they were set as integers.

figured it out that fx is only for devices for apps you use app.clearSetting or app.updateSetting

thanks

1 Like