Is it possible to disable a capability ui-component?

I am creating a driver/device for a thermostat, this one has the possibility of being locked, so that children do not modify the settings.

Is it possible to lock the user interface, gray it out, while retaining the ability to display the target and current temperature?

No, but you can manipulate it by switching the value back when its set through the UI.
See the Device capability app sourcecode on bitbucket and look for the disabled button.

Make sure to use a timeout within the trigger Runlistener to switch the value back, the RunLisyener must be compelted before you can switch the value back.

Edit, also, it might work to override the capabilityOptions and set Setable:false.
Not sure if that will work, but it might be worth a try.

Okay, my answer “No” was to fast:
Add this to your

"capabilities": {
    "target_temperature":{"value":20,"type":"number","getable":true,"setable":false,"title":"Room 1 Temperature","units":"°C","decimals":2,"min":4,"max":35,"chartType":"stepLine", "uiComponent":"thermostat"}

If you do this, you will get a warning when you try to change it:

So, you can do this the ‘normal’ way.

But what you also can do is how i do it with Device Capabilities’ AVDs.
I just set that value back within the RunListener:

if (settings[fieldId + 'Disabled'] !== true) 
	this.registerCapabilityListener(cap, (async (value, options) => {					
		let oldValue = this.getStoreValue(fieldId+"Value");				
		let val = this.getStoreValue(fieldId + "Value") === true;
		return setTimeout(async () => {
			await this.setCapabilityValue(cap, val);						
		}, 1);

And, btw, fyi:
I will be implementing a Disable function for my Advanced Virtual Devices’ Thermostats.
So perhaps those are an option for you.

And, many thanks for giving me a great new idea:
I will implement a feature in DC’s AVDs so you can use the thermostat as a combination-dial: put in the right numbers to activate a flow (and perhaps enable the normal funtions of the thermostat)!
And turn the dial to the end/configurable-number/combination-of-numbers, and it locks again :slight_smile:

Ok thank you, I will test!
Glad to have participated

1 Like