Passing multiple command values through from widget

Am I going crazy?

I want to pass two command values from a widget Automation Command Button to a rule and then use those values.

I have set-up the AC as follows (for testing):
image

And I have setup the rule as follows:

But this message shows as:
image

The rule debugger shows this:
image

What am I doing wrong? How can I pass through and use two values from a widget command button and use the values independently in a rule?

Enter them directly comma separated. No need to do =. There is no such thing as named values. They are values if the command name.

So you would enter MyName,BCD

Ahh, thanks @Jesse… So how do I access them in the rule? How can I access the first and second parameters separately?

You can’t. You need to do two commands.

OK, that seems really strange that it is possible to do via EXECUTE AUTOMATION COMMAND and it is also possible with the buttons insider a Ticket Lister widget.

@emre Are you planning to implement multiple command values for Automation Command Button widgets in the future?

How would you suggest it work? Multiple names for command values? The command is the name.

Your not though your defining a command name with value. None of those cases is allowing command value names.

You need something other than command button.

How would you feed the command those values. I think your confused.

That was something I’ve implemented for Ticket Lister. I can add it to button widgets too.

I added it for the next update. Thank you very much for reporting.

2 Likes

How are you choosing entity type though? Isn’t it hard cosed to that button?

No, those values were just for me to test things. The f I couldn’t pass static values I knew I would be able to pass dynamic values.

I’m confused though how would you specify which value if it’s just one button press. Maybe feeding the name to the button first?

It will allow me to have a series of buttons on an entity screen all triggering just one rule. Then within that rule a bunch of logic can happen using several variables. For example I can setup a bank of buttons to set “fresh” or “not fresh” for a bunch of different things like apples, bananas and oranges… This would be a total of 6 buttons each two different hard coded variables. This way the user can click any of these buttons to immediately set the state of a particular thing.

Can you try it with latest beta?

Sounds like a menu to me LOL :yum:

1 Like

If you click a single button that has two values how would it know which one you wanted?

No… This series of buttons is setting custom data values for specific entities.

Because each button is set-up on an entity screen to do a specific thing (setting a specific value in a specific entity)… The text displayed on each button is different, and that corresponds to the values that are going to be changed.

Thanks @emre, I will check it out soon :slight_smile:

@mjb2000 you posts last month got me thinking when I came to a similar scenario where I needed to pass several values through an execute automation command and I have come up with an alternate solution available now using scripts to pass multiple variables as JSON.

function newValues(input) {
	var input					=input.toString();
	var jsonArray				= {};
	var splitParams				= input.split(',');
	for (var p = 0; p < splitParams.length; p++) {
		var singleParam			= splitParams[p];
		var splitSingleParam	= singleParam.split('=');
		var paramName			= splitSingleParam[0].toString();
		var paramValue			= splitSingleParam[1].toString();
		jsonArray[paramName]	= paramValue;
	}
	return JSON.stringify(jsonArray);
}

function getValue(input,getValue){
	var jsonArray = JSON.parse(input);
	return jsonArray[getValue]
}

function addValues(input,newValues){
	if(input){
		var jsonArray = JSON.parse(input);
	}else{
		var jsonArray = {};
	}
	var splitParams				= newValues.split(',');
	for (var p = 0; p < splitParams.length; p++) {
		var singleParam			= splitParams[p];
		var splitSingleParam	= singleParam.split('=');
		var paramName			= splitSingleParam[0].toString();
		var paramValue			= splitSingleParam[1].toString();
		jsonArray[paramName]	= paramValue;
	}
	return JSON.stringify(jsonArray);
}

You would then place multiple values in the command value field using a CALL which will render as a JSON string for parsing in the rule later.

Using the above you could pass your Entity=MyName,EquipType=BCD as {CALL:commandValue.newValues('Entity=MyName,EquipType=BCD')}

Then in your rule you can call values back out of the JSON string using the getValue function ie;
{CALL:commandValue.getValue('[:CommandValue]','Entity')} and {CALL:commandValue.getValue('[:CommandValue]','EquipType')}

The scripts could probably do with some refinement and verification and you would need to be careful with special characters including quotes, double quotes, comma, colons and curly brackets which would interfere with JSON format.

Values should be entered as a comma separated list of name=value ie;
'<name1>=<value1>,<name2>=<value2>,<name3>=<value3>'
There is no limit to the number of name=value pairs.
In my example I used [?Prompt] for values to be entered but should be able to use most system variables available.


Calling values needs the JSON sting in [:CommandValue] input first followed by the name for the value you wish to call ie;
'[:CommandValue]','<name1>'

2 Likes