Creating a virtual dimmer switch
-
- Posts: 22
- Joined: Mon Jul 16, 2018 4:32 pm
Creating a virtual dimmer switch
I have created a virtual dimmer in Smartthings and given Webcore and EventGhost access to it. EG is on my computer. I have two pistons using the dimmer each sets the dimmer an a level (5 and 10) the thought is to use each level to trigger separate actions in EG on my PC. When i trigger either of the two in webcore both actions are triggered on my PC. I have noticed in EG on the left side it shows the dimmer and what level it is or was set at when I create the macro and drag that event over to the right side it shows st.STEventGhostDimmer.level but it does not show the number like on the left. I have tried to configure the event on the right side and manually type in the level but then it does not work at all
What am I doing wrong
Rick
What am I doing wrong
Rick
- kgschlosser
- Site Admin
- Posts: 5508
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Creating a virtual dimmer switch
Events are broken into several parts
Prefix Suffix Payload
the prefix is everything before the first "." or the whole event string if there is no "."
the suffix would be everything after the first "." up to the payload.
the separation between the suffix and the payload is the tricky bit of it.
the prefix and suffix are what make up the whole event string or "event"
in order to distinguish what is event and what is payload there are different things to look for.
these are the typical identifiers for the payload there is a space between the event and one of these markers as well.
u'
"
[
{
<
when dealing with numbers that are payload data how you are going to tell is simply by the space before the number.
payload data is not part of the event string and can only be accessed by using a python script. or by using a an expression that gets parsed
the expression that gets parsed can only be used in an action if it has been set up to do so. You can simply put the expression in and if the action has been set up to handle it the expression will get replaced with the value.
as an example. if you set up the OSD action and in the text entry field you type in {eg.event.payload} this text will get replaced with the actual payload value. remember the {}'s that is the identifier to an action to go and get the proper data.
if the action does not support parsing you will need to call the action from inside of a python script. This is really easy to do.
Create your action as you want. make note of the value you place where you want to put the payload data instead. if it is a text entry field type in HELLO. apply and save the action.
right click on the newly created action and in the menu that appears select copy as python.
now you want to create a Python Script action. in that action simply do a paste. this is going to drop in the python version of the action you set up.
now you should see something similar to this.
I am going to explain this series of things so you will know what to replace.
this is the action. I used the Show OSD action.
eg.plugins.EventGhost.ShowOSD()
each one of the items in between the ()'s is a parameter in the action. some settings in an action dialog may not be directly inserted as a parameter. but they will influence what the parameters are.
u'HELLO', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 5, (0, 0), 0, 3.0, None
parameters are seperated by a comma and a space. you have to take care when identifying the parameters because you can have a command and a space that is apart of a string, list, tuple or a dictionary. I will get into detail more on this in a second. as seen below i have separated the parameters
u'HELLO',
u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial',
(255, 255, 255),
(0, 0, 0),
5,
(0, 0),
0,
3.0,
None
now if you look at the above example you are going to see parameters that look like so (0, 0, 0) remember what i said above about the comma and the space. this has a comma and space as well but it is a single parameter not 3. You just need to take care and make sure that if the parameter starts with a (, {, [, ' or " the parameter needs to end with it. if you see a u' you can simply ignore the u it is a type of string formatting.
I know that this all sounds overly complex. but it really isn't. it will become second nature once you have spent a little time messing around with it.
so now we want to replace the HELLO parameter with the payload. you need to replace the whole parameter and not just the HELLO. the whole parameter is u'HELLO' make sure you delete the u and the single quotes as well.
if you have any questions or need help in any way tell me what plugin you are using and what action. and which field you would like to replace and i can walk you through it.
Prefix Suffix Payload
the prefix is everything before the first "." or the whole event string if there is no "."
the suffix would be everything after the first "." up to the payload.
the separation between the suffix and the payload is the tricky bit of it.
the prefix and suffix are what make up the whole event string or "event"
in order to distinguish what is event and what is payload there are different things to look for.
these are the typical identifiers for the payload there is a space between the event and one of these markers as well.
u'
"
[
{
<
when dealing with numbers that are payload data how you are going to tell is simply by the space before the number.
payload data is not part of the event string and can only be accessed by using a python script. or by using a an expression that gets parsed
the expression that gets parsed can only be used in an action if it has been set up to do so. You can simply put the expression in and if the action has been set up to handle it the expression will get replaced with the value.
as an example. if you set up the OSD action and in the text entry field you type in {eg.event.payload} this text will get replaced with the actual payload value. remember the {}'s that is the identifier to an action to go and get the proper data.
if the action does not support parsing you will need to call the action from inside of a python script. This is really easy to do.
Create your action as you want. make note of the value you place where you want to put the payload data instead. if it is a text entry field type in HELLO. apply and save the action.
right click on the newly created action and in the menu that appears select copy as python.
now you want to create a Python Script action. in that action simply do a paste. this is going to drop in the python version of the action you set up.
now you should see something similar to this.
Code: Select all
eg.plugins.EventGhost.ShowOSD(u'HELLO', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 5, (0, 0), 0, 3.0, None)
this is the action. I used the Show OSD action.
eg.plugins.EventGhost.ShowOSD()
each one of the items in between the ()'s is a parameter in the action. some settings in an action dialog may not be directly inserted as a parameter. but they will influence what the parameters are.
u'HELLO', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 5, (0, 0), 0, 3.0, None
parameters are seperated by a comma and a space. you have to take care when identifying the parameters because you can have a command and a space that is apart of a string, list, tuple or a dictionary. I will get into detail more on this in a second. as seen below i have separated the parameters
u'HELLO',
u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial',
(255, 255, 255),
(0, 0, 0),
5,
(0, 0),
0,
3.0,
None
now if you look at the above example you are going to see parameters that look like so (0, 0, 0) remember what i said above about the comma and the space. this has a comma and space as well but it is a single parameter not 3. You just need to take care and make sure that if the parameter starts with a (, {, [, ' or " the parameter needs to end with it. if you see a u' you can simply ignore the u it is a type of string formatting.
I know that this all sounds overly complex. but it really isn't. it will become second nature once you have spent a little time messing around with it.
so now we want to replace the HELLO parameter with the payload. you need to replace the whole parameter and not just the HELLO. the whole parameter is u'HELLO' make sure you delete the u and the single quotes as well.
Code: Select all
eg.plugins.EventGhost.ShowOSD(eg.event.payload, u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 5, (0, 0), 0, 3.0, None)
if you have any questions or need help in any way tell me what plugin you are using and what action. and which field you would like to replace and i can walk you through it.
-
- Posts: 22
- Joined: Mon Jul 16, 2018 4:32 pm
Re: Creating a virtual dimmer switch
Got it solved thanks
I had posted on WebCore about something else and aske there this is the answer I got if anyone else is interested
You just have to create one extra macro for it to work. (shown below)
Line 1 is: a Macro (with any name)
Line 2 is: the normal drag trigger (with no trailing stuff)
Line 3 is: Add Action > Python command
The python command on line 3 is:
eg.TriggerEvent("EgDimmer." + eg.event.payload[0])
What this does is when your Sim Dimmer changes, it triggers those 3 lines above.
That code strips the number at the end, and sends out a NEW trigger.
In other words, the “EgDimmer Retrigger” section only needs to be created once. The 2 samples below that are for whatever numbers you are using. (easy to copy/paste for new numbers in the future)
I had posted on WebCore about something else and aske there this is the answer I got if anyone else is interested
You just have to create one extra macro for it to work. (shown below)
Line 1 is: a Macro (with any name)
Line 2 is: the normal drag trigger (with no trailing stuff)
Line 3 is: Add Action > Python command
The python command on line 3 is:
eg.TriggerEvent("EgDimmer." + eg.event.payload[0])
What this does is when your Sim Dimmer changes, it triggers those 3 lines above.
That code strips the number at the end, and sends out a NEW trigger.
In other words, the “EgDimmer Retrigger” section only needs to be created once. The 2 samples below that are for whatever numbers you are using. (easy to copy/paste for new numbers in the future)
Re: Creating a virtual dimmer switch
Code: Select all
eg.TriggerEvent(prefix="EgDimmer", suffix=eg.event.payload[0])
- kgschlosser
- Site Admin
- Posts: 5508
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Creating a virtual dimmer switch
if you want to preserve the event and simply add the payload to the end of the event string
*** edited to make sure that the use of a wildcard would not cause a cascading issue in the event system.
Code: Select all
if not eg.event.string.endswith(str(eg.event.payload[0]): eg.TriggerEvent(prefix=eg.event.prefix, suffix=eg.event.suffix + '.' + str(eg.event.payload[0]), payload=eg.event.payload[:], source=eg.event.source)
*** edited to make sure that the use of a wildcard would not cause a cascading issue in the event system.
Re: Creating a virtual dimmer switch
kg, you should sticky that. This question seems to come up a lot. That's a good one liner for forwarding the payload as a suffix.
- kgschlosser
- Site Admin
- Posts: 5508
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Creating a virtual dimmer switch
Don't know where I should put it.
Re: Creating a virtual dimmer switch
IDK, code exchange or coding corner.