I want to use Alexa routines as it allows me to say “I am leaving”. I don’t want to use Amazon routine mechanism as it is very limited. I want to trigger rule / script in Openhab.
The way I see to implement it is to define Routine switches, e.g.:
rule "Alexa routine"
when
Member of Alexa_Routine received command
then
val script = transform("JS", "routines.js", triggeringItem.name.toString)
callScript(script +".script")
end
That uses the transform to map routine to script name:
(function(i) {
var map = {
"Alexa_Routine_0": "leaving"
}
var name = map[i];
if (name) {
return name;
} else {
return "unknown"
}
})(input)
But since your JS transform just does a mapping, why not just use the Map transform?
You could even drop the map and name the routine Item and script the same. Then you can use:
callScript(triggeringItem.name+".script")
As a bonus the Items could end up with more meaningful names. I strongly recommend using meaningful names where ever possible so you can tell, just by looking at the name of the Item, that this Switch controls your “leaving” routine.
Yes, I can use the map transform. Just personal preference to use JS … (Is JS slower then MAP BTW?)
Yes, I can drop and call the script directly, but I didn’t want it this way as I am trying to decouple things, and using PROXY here seems to me more accurate.
The benefit of using patterned names, is that I don’t need to discover items every time I do a change or change Alexa routine.
I can agree with u about meaningful names, but in this case I assume documentation can replace it (assuming u document your code )