Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing device name as variable
#1
Think I have asked this before, but now can't remember how to accomplish this.  

I want to write a single global action that covers setting setting any single light requests using Alexa.  Rather than using duplicate code for each light, I can just setup the echo global action to then pass the device name (for example: ELK-M1.LGHT#Dim_Main_Kitchen_Eat-in), text for echo response, and the value to the single global lighting action that will then use the passed parameters to set the light passed as parm_1.

The problem is when I try to use parm_1 to load the value into a variable.

What I am trying to do:

LocalVars::SetVariable
    P1=LVar:Light_Level
    P2=$(%(LVar:CQCActParm_1))   <-----This fails - What is the proper syntax?  



If entered directly:

LocalVars::SetVariable
    P1=LVar:Light_Level
    P2=$(ELK-M1.LGHT#Dim_Main_Kitchen_Eat-in)
Reply
#2
LocalVars::SetVariable
P1=LVar:Light_Level
P2=%(LVar:CQCActParm_1)

$ is used to dereference a field name
% is used to dereference a variable name
Wuench
My Home Theater/Automation Website

[THREAD=5957]BlueGlass CQC Config[/THREAD]
[THREAD=10624]Wuench's CQC Drivers[/THREAD]
Reply
#3
Understood, but in the this case LVar:CQCActParm_1 contains the field name that needs to be dereferenced to set the value of L_Var:Light_Level.  The text you provide will only set LVar:Light_Level to "ELK-M1.LGHT#Dim_Main_Kitchen_Eat-in".  I want LVar:Light_Level set to the current value of that field.
Reply
#4
Use ReadField or ReadField2 to read the value. In that case, you can pass in the name of the field as a parameter, and get the value back out in variable.
Dean Roddey
Software Geek Extraordinaire
Reply
#5
Now I remember.  Thanks.

Another quick question.  When using Alexa to set something to a specific number, is there an easy way to convert the text to a numerical value?  For instance when you say "fifty", it returns fifty, not 50.  Would like to do things like set thermostat to 70, or set lighting to 40%.  Do I have to create a function to do the conversion, or is something already built-in?
Reply
#6
I wrote a helper macro to do that a while back, and posted it here on the forum. But I'm blanking on what it was called. Maybe someone else remembers that. I do need to make it a built in command.

Oh, nevermind, it maybe shipped. Look for:

/User/CQC/Num2Num

You pass parameters like this:

"one hundred fifty two", "GVar:Result", L"GVar:ErrMsg"

So the numeric value to convert, a variable name to put the resulting number in, and an error msg variable if it fails. It returns true if it works and false if it fails so you can check the result.

If it's not shipped I can create you a package. I'll push it up on my list of smaller things I can take on for the next drop to get that done as a built in.
Dean Roddey
Software Geek Extraordinaire
Reply
#7
Okay, so I found the Num2Num macro and installed the macro pack.  Now having some issues implementing it.  Below is a example of what I'm trying to do.  The first if is to determine if Parm_3 is a number value...  If so, then write the level to the device field.  If it is not then test for specific key words to perform set actions.  

This format does not error on save, but clearly is not working correctly.  It executes, but does not return the error message and always falls to execute the device write (falls out the else).  What am I doing wrong?



If 
MacroEng::RunMacro
    P1=MEng.User.Num2Num
    P2=%(LVar:CQCActParm_3), "GVar:Light_Level_Num", "LVar:ErrMsg" 

Devices::FieldWrite
    P1=%(LVar:CQCActParm_1)
    P2=%(GVar:Light_Level_Num)
    P3=True

-GlobalVars::SetVariable
    P1=GVar:EchoReply
    P2=%(LVar:ErrMsg)

-GlobalVars::SetVariable
    P1=GVar:EchoReply
    P2=%(LVar:Light_Level)

Else

'Do other stuff
Reply
#8
Okay, so I am using the below syntax and it runs and will return (say "Set Value"), but if I try to do anything with GVar:Light_Level_Num, it will fail.  The error that shows in log is "Token expansion failed during command processing"  Also, if I use anything longer than 1 word, it fails to execute the macro claiming I am passing more than 3 parameters.

If 
MacroEng::RunMacro
    P1=MEng.User.Num2Num
    P2=%(LVar:CQCActParm_3), GVar:Light_Level_Num, LVar:ErrMsg

GlobalVars::SetVariable
    P1=GVar:EchoReply
    P2=Set Value

Devices::FieldWrite
    P1=%(LVar:CQCActParm_1)
    P2=%(GVar:Light_Level_Num)
    P3=True

Else

GlobalVars::SetVariable
    P1=GVar:EchoReply
    P2=Fell out Else

End
Reply
#9
In this part, try this:

Code:
MacroEng::RunMacro
    P1=MEng.User.Num2Num
    P2="%(LVar:CQCActParm_3)" GVar:Light_Level_Num LVar:ErrMsg

I.e. it's not a comma separated list of values, it's just space separated, and quote the first one since it will likely have spaces in it, and you need it to be treated like a single value.

If the macro fails, it will won't set the variable value, so if it doesn't already exist it won't get created.
Dean Roddey
Software Geek Extraordinaire
Reply
#10
Okay, so I think that fixed the error, but still not returning any values.  Perhaps this is what your last line is referring to.  

The odd thing is that the behavior is opposite to expected.  If I send it a real value, "ten" for instance, it falls through to the else statement.  If I send it a non-numerical text, like "up" for instance, it executes returning 0 or making no change.

GlobalVars::CreateVariable
    P1=GVar:Light_Level_Num
    P2=Int
    P3=
    P4=0

LocalVars::CreateVariable
    P1=LVar:ErrMsg
    P2=String
    P3=
    P4=Null

If 
MacroEng::RunMacro
    P1=MEng.User.Num2Num
    P2="%(LVar:CQCActParm_3)" GVar:Light_Level_Num LVar:ErrMsg

GlobalVars::SetVariable
    P1=GVar:EchoReply
    P2=Set Value to %(GVar:Light_Level_Num)

Else

GlobalVars::SetVariable
    P1=GVar:EchoReply
    P2=Error Message %(LVar:ErrMsg)

End
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Variable Driver Trigger Error zra 4 749 07-06-2017, 01:00 PM
Last Post: zra
  Device Driver documentation Bugman 3 689 06-01-2017, 05:16 PM
Last Post: Dean Roddey
  Echo is passing numbers as text so it cant be written to a field - any fix? ghurty 9 1,100 07-03-2016, 08:05 AM
Last Post: ghurty
  Inserting global variable into command string MikeA 2 529 06-26-2016, 10:09 AM
Last Post: MikeA
  Z-Wave Device config GoControl Door/Window Sensor batwater 50 3,557 03-09-2016, 01:21 PM
Last Post: Dean Roddey
  Set Variable field with Slider (Variables driver) pinballmark 2 717 08-28-2015, 01:55 PM
Last Post: pinballmark
  Problem with OmniPro II device dlmorgan999 3 599 07-26-2015, 08:07 PM
Last Post: dlmorgan999
  Variable Find action? dlmorgan999 3 708 05-21-2015, 05:00 PM
Last Post: dlmorgan999
  Device Driver docs? IVB 3 753 02-19-2015, 05:02 AM
Last Post: EST
  What command would I use to write a field value to a variable? ghurty 4 804 01-28-2015, 02:57 PM
Last Post: znelbok

Forum Jump:


Users browsing this thread: 1 Guest(s)