Changes

3,456 bytes added ,  14:34, 28 November 2023
no edit summary
Line 40: Line 40:  
</pre>
 
</pre>
 
You can then use the values of interest from the dictionary in your macros, for example to populate a weather summary from a weather API or similar.
 
You can then use the values of interest from the dictionary in your macros, for example to populate a weather summary from a weather API or similar.
 +
 +
A more complex example:
 +
<pre>
 +
 +
{
 +
  "Body" : {
 +
      "Data" : {
 +
        "Inverters" : {
 +
            "1" : {
 +
              "Battery_Mode" : "suspended",
 +
              "DT" : 83,
 +
              "E_Day" : 215.89999389648438,
 +
              "E_Total" : 7790457,
 +
              "E_Year" : 2533685,
 +
              "P" : 32,
 +
              "SOC" : 6.8000001907348633
 +
            }
 +
        },
 +
        "Site" : {
 +
            "BatteryStandby" : true,
 +
            "E_Day" : 215.90000000000001,
 +
            "E_Total" : 7790456.9000000004,
 +
            "E_Year" : 2533685,
 +
            "Meter_Location" : "grid",
 +
            "Mode" : "bidirectional",
 +
            "P_Akku" : 0,
 +
            "P_Grid" : 371.16000000000003,
 +
            "P_Load" : -403.16000000000003,
 +
  -->      "P_PV" : 55.719999999999999,
 +
            "rel_Autonomy" : 7.9372953666038288,
 +
            "rel_SelfConsumption" : 100
 +
        },
 +
        "Version" : "12"
 +
      }
 +
  },
 +
  "Head" : {
 +
      "RequestArguments" : {},
 +
      "Status" : {
 +
        "Code" : 0,
 +
        "Reason" : "",
 +
        "UserMessage" : ""
 +
      },
 +
      "Timestamp" : "2023-11-28T14:47:38+01:00"
 +
  }
 +
}
 +
</pre>
 +
The above JSON table is used in this example. The value which will be selected is P_PV, the one marked by --> in the printout.
 +
 +
If the JSON content is stored in local string variable Vjson click ‘Parse JSON’ from the ‘Add Action’ menu, part ‘MacroDroid Specific’ and choose Vjson as ‘Input String Variable’ and  Djson as ‘Output Dictionary Variable’ by click on the + symbol. Thereafter Djson can be put to live by a click on ‘JSON Parse’ in the Action window and a further click on ‘Test action’ in the new opened window. 
 +
 +
A click on Djson in ‘Local Variables’ at the bottom of the screen shows two entries: ‘Body’ with one entry and ‘Head’ with two entries.  A click on ‘Body’ opens a new window with three new entries: ‘Inverters’, ‘Site’ and ‘Version’, each coming with their number of new sub entries. A click on ‘Site’ opens in this case 12 values, each already analysed by content (Boolean, Decimal, Integer and String). Compare it with the printout to get an idea of the JSON structure.
 +
 +
The next action after ‘JSON Parse’ is ‘Set Variable’ from the ‘Add Action’ menu part ‘MacroDroid Specific’. Give it a name for instance ‘PV’ but never P_PV to avoid conflicts.
 +
As P_PV is numeric either Integer (if fractions are of no importance) or Decimal has to be selected. Close the window and select ‘Expression’ in the next window. Click in the blue field right to the ‘Enter value’. In the new window select ‘LocalVar:Djson’ as option. After OK a window ‘Select Dictionary Entry’ opens showing ‘Define Manually’ (for experienced users) and the two main entries [Body] and [Head] of the JSON table. Select Djson[Body]. Proceed to Djson[Body][Data], Djson[Body][Data][Site] and finally select Djson[Body][Data][Site][P_PV]. The ‘Set Variable’ row in the Action window reads after this
 +
 +
PV:{lv=Djson[Body][Data][Site][P_PV]}.
 +
 +
To verify the total action click in the ‘Actions’ window on ‘Set Variable’ and click then on ‘Test Action’. If all went correct the Variable PV in the ‘LocalVariables’ window will show 58, omitting the fractions because PV was declared as integer. Be aware that there might be a problem with the decimal point because in some countries a comma is use instead.
editors
36

edits