I am using the garage door widget from rlkoshak (thanks!) and I would like to add a confirmation popup. This is in case I accidently click on the widget. Here is the code:
uid: rlk_garagedoor_list
tags:
- list
- garagedoor
props:
parameters:
- description: Door name
label: Name
name: name
required: false
type: TEXT
- context: item
description: Control Item
label: Control Item
name: control_item
required: false
type: TEXT
- context: item
description: Sensor Item
label: Sensor Item
name: sensor_item
required: false
type: TEXT
parameterGroups: []
component: oh-list-item
config:
icon: '=(items[props.sensor_item].state == "CLOSED") ? "f7:house" : "f7:house_fill"'
iconColor: '=(items[props.sensor_item].state == "CLOSED") ? "green" : "red"'
title: =props.name
action: command
actionItem: =props.control_item
actionCommand: ON
badgeColor: '=(items[props.sensor_item].state == "CLOSED") ? "green" : "red"'
badge: '=(items[props.sensor_item].state == "CLOSED") ? "closed" : "open"'
I did find some info about popups in widgets but I have no idea how to apply the solutions I found to this widget, I am a newbie with widgets.
I’ve not done this but I think what you need at a minimum is to change the action to popup and then add the actionModal properties which point to the widget to show when it’s clicked. That widget will need to be defined separately and in that widget you’ll need two buttons, one which cancels and does nothing but close the dialog and the other which commands the Item.
Beyond that general outline I’m not going to be of much help. It’s not something I’ve tried.
If you are on a recent OH4 version, then you can do this automatically just by using the actionConfirmation property.
If you have something more complex than a simple confirmation dialog box, then you will need to go with the action: popup settings. You can find description and examples here:
You have put quotes around the object. Your expression is resulting in an error because the attempt to parse that gets you the string { followed by no operation and a then a call to a variable type (which of course doesn’t exist).
Is is more quotes around the object. I had meant to indicate that you want no quotes around it.
This is always a YAML parser error not a js expression error. This means that somewhere in the value to a property you have a : followed by a space which the YAML parser is trying to make into a new key: value definition.
When you added single quotes to the expression which already had single quotes around it you didn’t get a string inside another string you got [string] bunch of stuff in between [second string] and in that bunch of stuff in between is your object definition which has many : instances that are causing the YAML error.
You’re object shouldn’t be a string anyway. Inside the expression an string is not the same thing as an object. If you’re expression didn’t have errors causing the entire thing to fail you would have gotten a dialog with your object definition as the text of the dialog because that’s what happens when actionConfirmation has a string for a value.
I would do this expression like this. Your first requirement is that you want a value to the property only when some test is true. A ternary expression is not the best fit here (it works, but the when false then false at the end is extraneous). Actually you just want to use logical AND && as a clean shortcut. In javascript the && operator will always just evaluate the first value initially and return false if that value is false (because AND already cannot be true if the first value is false). If the first value is true then && returns the second value itself (if that value is true then the && is true and if that value is falsy then && is false). So test && some_value is always “return some_value if test is true otherwise return false”: exactly what you want.
Then you just have to remember that the value you want to return is an object (not a string) and your expressions is
Single quotes around the entire express prevent the YAML parser from getting stuck on the: in the object definition, and there are no quotes around the {...} because that would make your object a string instead.
Which works for the false condition, so if the Partition is not Arned.
However when the Partiton is Armed, when the conformation should be displayed, nothing happens, The confirmation does not disply and no error is logged at all.
Ok, your expression should have worked so I had to take a quick look at the ui repo. The widget actions were refactored a few months ago and now it looks actionConfirmation doesn’t actually process objects directly and only accepts strings. If the string is a JSON string then that string is parsed into an object. This is why your basic test of your object (which you still had set as a string) worked, but the form of the expression I gave you does not. The fix for now is quick. You do not need the single quotes around the entire expression. You only need the single quotes around the object definition itself:
@florian-h05 I’m still not 100% solid on reading through typescript quickly, but it looks to me that in the widget action typescript refactor the ability to set the confirm config directly from a JSON (or YAML) object was lost so that now only strings and stringified objects are valid here. Am I correct, and was this intentional?