Beiträge von Salt1977

    How do you mean "accessing via http"? Currently scripts can publish internal information via HTTP GET or POST. Or they can listen to MQTT topic and publish to one.
    But given the above it is rather publishing via HTTP or MQTT and yes, this is very much doable.

    i meant to call e.g., http://192.168.2.xxx/rpc/Script.Start?id=1 and then have the script "print" a json object to the browser which would be something like

    {"total_power" = 1200.2)

    This works:

    Shelly Script is asynchronous as generally JavaScript is. As the code is single threaded, the ability to provide delayed execution is achieved via callbacks, invoked when a synchronous (Timers) or asynchronous(RPC, HTTP calls) events occur.

    So in the provided example the printing of values outside of the callback happens before the callback is executed. If you need to use the results of the response call a function from within the callback.

    Thanks Mircho. Do you have an idea if my request (summing up power utilization across channels and accessing this via http / rpc request) is somehow doable via the onboard scripting?

    Same behaviour, my console output is:

    ---

    Step 1 - r2: {"volt":0,"temp":0}18:01:45.660

    Step 3 - r2 {"volt":0,"temp":0}18:01:45.672

    r: {"temperature":{"tF":105.700000,"tC":41},"aenergy":{"minute_ts":1642438904,"by_minute":[592.156000,788.928000,789.454000],"total":742.088000},"pf":-0.470000,"current":0.317000,"voltage":231.300000,"apower":46.500000,"output":true,"source":"init","id":0}18:01:45.757

    Step 2 - r2: {"volt":231.300000,"temp":41}

    ---

    I unfortunately have zero experience with ShellyPro Scripting, but want to get a similar (albeit slightly different) result as you are looking for -- I want a way to "ask" via http for the power consumption sum of all four meters, returned ideally via a JSON object.

    But I don't really understand the syntax of the scripting and how I could then do a http request to get the summary from the device.. :-/ can you help, given that you're clearly ahead of me in regards to writing scripts?

    Hi all,

    I installed a Shelly Pro4PM, and wanted to ask the community if there is a simple way to get via http-RPC call a „Total Power currently used across all channels“, similarly to the total_power field you can get on the 3EM within the http://Shelly_IP/status JSON object. If it‘s not „out of the box“, has anybody written a Shelly Script to create such a value „on the device“, i.e., without the need to ask each channel separately via http through http://Shelly_IP/rpc/Switch.GetStatus?id=Channel_ID and then compute on the requesting end… ? Or a script to sum up specific channels?

    Thanks for any pointers!

    Cheers

    Stefan