You are welcome. Look forward to it.
the set level command seems to turn light bulbs on as well. is there a way to set level without turning on the light bulb?
Thanks!
Nope. As far as I know, that’s the way way it works.
Couple of things for you to know.
Don’t define a variable at the top with any data if you plan on setting that variable as something in the piston. Just set the variable type for what you want to store and give it a name like you did with your dupe flag.
Don’t use the $sunset and $sunrise variables. There are presets that you can choose instead. Check the virtual list.
Webcore changed from CoRE in how actions get executed. By default everything is now synchronous. If you change your with statements to async then webcore will continue past your waits to the next with statement.
If you make those changes your piston should work as is
Hi, @c1arkbar. Can you elaborate, please? Is this just a matter of “clean” programming, or does initializing a variable prevent or control some future ability to set values in the piston?
People seem to skip over this note when assigning a value to a variable in the top section. There are plenty of cases where you would want something up there defined throughout every piston run. But if you plan on using that to store information that you later want to act on then your piston will never work correctly.
Im trying to turn off my TV with a web request to my RPi. What is the correct way to format a request? Or do you guys see if there is something else which is wrong?
Here is the piston.
And here is the log:
+0ms ╔Received event [Home].routineExecuted = 55561ee4-4e5b-488d-acdb-8c157a39d05e with a delay of 67ms
+177ms ║Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+178ms ║Calculating (string) command : (string) standby >> (string)
+185ms ║Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+186ms ║Calculating (string) addonid : (string) script.json-cec >> (string)
+191ms ║Calculating (string) , (string) params >> (string) params
+195ms ║Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+196ms ║Calculating (string) params : (string) >> (string)
+204ms ║Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+205ms ║Calculating (integer) 0 : (integer) 1 >> (integer)
+212ms ║Calculating (integer) 0 , (integer) 0 >> (integer) 0
+218ms ║Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+219ms ║Calculating (decimal) 0.0 : (decimal) 2.0 >> (decimal)
+225ms ║Calculating (decimal) 0.0 , (decimal) 0.0 >> (decimal) 0.0
+231ms ║Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+232ms ║Calculating (decimal) 0.0 : (decimal) 0.0 >> (decimal)
+237ms ║Calculating (decimal) 0.0 , (decimal) 0.0 >> (decimal) 0.0
+241ms ║Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+242ms ║Calculating (decimal) 0.0 : (decimal) 0.0 >> (decimal)
+247ms ║Calculating (string) request= + (string) 0.000000 >> (string) request=0.000000
+250ms ║RunTime Analysis CS > 17ms > PS > 68ms > PE > 166ms > CE
+260ms ║Runtime (33051 bytes) successfully initialized in 68ms (v0.2.0bc.20170611) (258ms)
+261ms ║╔Execution stage started
+275ms ║║Comparison :ad65e14910f106961ef17f59e7ebef37: executes :ad65e14910f106961ef17f59e7ebef37: = true (3ms)
+278ms ║║Cancelling condition #4’s schedules…
+279ms ║║Condition #4 evaluated true (9ms)
+280ms ║║Cancelling condition #1’s schedules…
+281ms ║║Condition group #1 evaluated true (state changed) (12ms)
+284ms ║║Cancelling statement #2’s schedules…
+299ms ║║Sending internal web request to: XXX.XXX.XXX.XXX:XXXX/jsonrpc
+301ms ║║Executed virtual command httpRequest (8ms)
+305ms ║╚Execution stage complete. (45ms)
+313ms ╚Event processed successfully (314ms)
If accessing:
http://XXX.XXX.XXX.XXX:XXXX/jsonrpc?request={“id”:1,“jsonrpc”:“2.0”,“method”:“Addons.ExecuteAddon”,“params”:{“addonid”:“script.json-cec”,“params”:{“command”:“standby”}}}
from a web browser, it works fine.
And if running:
curl -v -H “Accept: application/json” -H “Content-type: application/json” -d ‘{“id”:1,“jsonrpc”:“2.0”,“method”:“Addons.ExecuteAddon”,“params”:{“addonid”:“script.json-cec”,“params”:{“command”:“activate”}}}’ http://XXX.XXX.XXX.XXX:XXXX/jsonrpc
From a command line, it also works fine.
I’ve tried removing the “request=” in the variable. Would be really grateful if someone could take a look.
I believe it’s something to do with the data in req variable. I ran into the same issue yesterday where the json info is not being treated as a string. We’ll probably just need to wait until it gets fixed.
Looks fixed in v0.2.0bc.20170611 - BETA M2. Thanks ady624!
Okey, thanks!
@c1arkbar did something change in the code since yesterday? when I tried it about 24 hours ago it didn’t seem to work as is by removing initialization of the device variables in the define section and changing to async.
@lflorack i am seeing a funny thing when i try to edit your piston, looking for some help to clear it up. when editing statements like these:
set variable {ChandelierLevel} = Dimmer 1’s level;
set variable {ChandelierSwitch} = Dimmer 1’s switch;
for me they change to:
set variable {ChandelierLevel} = Dimmer 1;
set variable {ChandelierSwitch} = Dimmer 1;
In the UI I don’t see a way of specifying that ChandelierLevel should store Dimmer 1’s level and ChandelierSwitch should store Dimmer 1’s switch only.
Do you have an option in the UI that let’s you specify not just the device to store but also the attribute of the device to store? If not, how are you able to specify the level and the switch in those set variable statements?
Thank you.
also, when using the Set level or Set switch command I can now see in the UI there is a option to pick value and specify the attribute as in the screenshot below. Did these get added in the last 24 hours? When editing related pistons 24 hours ago don’t remember these showing up. Thanks!
All values in webCoRE are a hybrid dynamic weird type that supports a combination of the following, depending on what you’re doing:
- physical device (one or many, aggregated or not) + attribute
- virtual device
- variable
- value
- expression
- argument (picks up a value given to the piston by the event running it)
- preset (for colors, a list of colors, for time, a list of midnight, noon, sunrise, sunset)
You can directly set a device level or switch or anything else to another device’s attribute (any attribute you want). There is also an implicit conversion via boolean, so that if you say Set switch to Door’s contact, the light will turn on when the door opens and off when it closes. There is a list of strings that evaluate to true (open, on, true, active, present, detected, etc.) and a list of strings that evaluate to false (the negation of the ones that give true: closed, off, false, inactive, not present, clear, etc.)
That is a core feature of webCoRE and was not added yesterday
Ok, the problem is that { is a special character in webCoRE and needs to be escaped for it to not trigger an expression evaluation. I’m adding that option now, you should try escaping all { and } with \{ and \}
Also, from a JSON standpoint of view, “id”: 1 is missing double quotes around the 1.
Also, when JSON will be formatted for output, the name of the variable will be automatically output, so you may not really be able to send a custom JSON string that way, unless I add a new content type, RAW, where I’ll simply output the value of the variable.
thanks @ady624. its just personally weird for me because i somehow did not see those attribute selections when in the UI when editing those set level and set switch tasks yesterday. probably because i was doing something differently. referring to this post here:
also, i am still puzzled on this one. when editing statements like these from the piston @lflorack shared :
set variable {ChandelierLevel} = Dimmer 1’s level;
set variable {ChandelierSwitch} = Dimmer 1’s switch;
for me they change to the following if i try to edit them:
set variable {ChandelierLevel} = Dimmer 1;
set variable {ChandelierSwitch} = Dimmer 1;
In the UI I don’t see a way of specifying that ChandelierLevel should store Dimmer 1’s level and ChandelierSwitch should store Dimmer 1’s switch only. what am i doing wrong here?
Thank you.
Can’t help you much without a snapshot to import and see. What type are those variables?
Thanks! Just tried escaping all {} and put the 1 in double quotation, I don’t really understand that about the variable will be automatically output. I tried both with and without the “request=” before the json data. Is there another (working) way to send json requests?
You need to hard reload the page before editing the piston to escape the string - you might have done that already, as I just published the JS code. the problem is, with a JSON content type, I’ll be outputing
{"var_name": "var_value"}
where var_value is replaced with your string. It appears you need a FORM content and the variable needs to be named request. This way, the POST body will be:
request=var_value
where, again, var_value will be the string you set that variable to. What do you need to send? the ?request= implies a GET.
sorry. this is the piston from @lflorack i imported and was editing:
Based on this, I’d try with a GET request, escape the { and the } and then try again. If you hard reloaded, it should work and not complain about any errors while editing that string. Then the HTTP request should be a GET with no variables selected, the URL set to:
http://xxx.xxx.xxx/jsonrpc?request={req}
assuming you haven’t renamed the variable. If you did, replace {req} with whatever {varname} you used.