Sunrise-Sunset and Calendar functions for edge

Hi @nayelyz
In case it can help in your report.
I have been looking at the routines in @TAustin Browser+ API in JSON format and I think the error is only in the routines that use a precondition with a Interval condition and multiple conditions with an OR condition.
If the precondition has a condition it is: equal, greater or equal or less than or equal everything works fine.

Here is an example of a routine with a temperature interval precondition combined with two switch conditions = on with AND. Everything works fine Fine.

  • The precondition is distinguished by the value “trigger”: “Never”

  • The trigger conditions have the value “trigger”: “Always”

  • The IF: { AND: [ … ] condition affects the precondition and the two AND conditions.
    The precondition has “trigger”: “Never” and therefore never triggers the execution of the Then part until the two conditions that have “trigger”: “Always” are met.

{
  "if": {
    "and": [
      {
        "between": {
          "value": {
            "device": {
              "devices": [
                "16fa2ff4-00ca-4b65-b1db-5af142511d65"
              ],
              "component": "main",
              "capability": "temperatureMeasurement",
              "attribute": "temperature",
              "trigger": "Never"
            },
            "type": "device"
          },
          "start": {
            "decimal": 23,
            "type": "decimal"
          },
          "end": {
            "decimal": 26,
            "type": "decimal"
          },
          "changesOnly": false
        },
        "type": "between"
      },
      {
        "equals": {
          "left": {
            "device": {
              "devices": [
                "01caa709-9547-4bd2-b833-1aedeaa57d8d"
              ],
              "component": "main",
              "capability": "switch",
              "attribute": "switch",
              "trigger": "Always"
            },
            "type": "device"
          },
          "right": {
            "string": "on",
            "type": "string"
          },
          "changesOnly": false
        },
        "type": "equals"
      },
      {
        "equals": {
          "left": {
            "device": {
              "devices": [
                "1d33051b-2218-4f82-a81b-911d6a46c9a9"
              ],
              "component": "main",
              "capability": "switch",
              "attribute": "switch",
              "trigger": "Always"
            },
            "type": "device"
          },
          "right": {
            "string": "on",
            "type": "string"
          },
          "changesOnly": false
        },
        "type": "equals"
      }
    ],
    "type": "and",
    "then": [
      {
        "notification": {
          "push": {
            "title": "Termostato, Temperatura: 23~26°C",
            "message": "Temperature interval 23° to 26°"
          },
          "type": "push"
        },
        "type": "notification"
      }
    ],
    "sequence": {
      "then": "Parallel",
      "else": "Parallel"
    }
  },
  "type": "if"
}

Here is an example of a routine with a temperature Interval precondition, combined with two switch conditions = on with OR. It is fired when any of the OR conditions even if the precondition does not meet:

  • The IF: { OR: [ … ] condition affects the precondition and the two OR conditions. the precondition has “trigger”: “Never” and therefore does not trigger.
    It never triggers the execution of the Then part, but it should prevent any of the conditions that have “trigger”: “Always” from triggering the execution if its interval precondition is not fulfilled. Then part However is triggered because it is all included within the same IF: { OR: [ … ]
{
  "if": {
    "or": [
      {
        "between": {
          "value": {
            "device": {
              "devices": [
                "16fa2ff4-00ca-4b65-b1db-5af142511d65"
              ],
              "component": "main",
              "capability": "temperatureMeasurement",
              "attribute": "temperature",
              "trigger": "Never"
            },
            "type": "device"
          },
          "start": {
            "decimal": 23,
            "type": "decimal"
          },
          "end": {
            "decimal": 26,
            "type": "decimal"
          },
          "changesOnly": false
        },
        "type": "between"
      },
      {
        "equals": {
          "left": {
            "device": {
              "devices": [
                "01caa709-9547-4bd2-b833-1aedeaa57d8d"
              ],
              "component": "main",
              "capability": "switch",
              "attribute": "switch",
              "trigger": "Always"
            },
            "type": "device"
          },
          "right": {
            "string": "on",
            "type": "string"
          },
          "changesOnly": false
        },
        "type": "equals"
      },
      {
        "equals": {
          "left": {
            "device": {
              "devices": [
                "1d33051b-2218-4f82-a81b-911d6a46c9a9"
              ],
              "component": "main",
              "capability": "switch",
              "attribute": "switch",
              "trigger": "Always"
            },
            "type": "device"
          },
          "right": {
            "string": "on",
            "type": "string"
          },
          "changesOnly": false
        },
        "type": "equals"
      }
    ],
    "type": "or",
    "then": [
      {
        "notification": {
          "push": {
            "title": "Termostato, Temperatura: 23~26°C",
            "message": "Temperature interval 23° to 26°"
          },
          "type": "push"
        },
        "type": "notification"
      }
    ],
    "sequence": {
      "then": "Parallel",
      "else": "Parallel"
    }
  },
  "type": "if"
}

Here is an example of a routine with precondition with temperature <= at 18ºC, combined with two switch conditions = on with OR. It is triggered only when any of the OR conditions and the precondition of temperature <= 18ºC are fulfilled:

  • The condition IF: { AND: [ … ] affects the precondition of temperature <= 18ºC. The precondition has “trigger”: “Never” and therefore never triggers execution of the Then part.
    The IF: { OR: [ … ] condition only affects the switch = on conditions and therefore prevents any of the conditions that have “trigger”: “Always” from firing Then part if it does not meet precondition temperature <= 18ºC, since its relationship with the precondition is an IF: { AND: [ … ]
{
  "if": {
    "and": [
      {
        "lessThanOrEquals": {
          "left": {
            "device": {
              "devices": [
                "16fa2ff4-00ca-4b65-b1db-5af142511d65"
              ],
              "component": "main",
              "capability": "temperatureMeasurement",
              "attribute": "temperature",
              "trigger": "Never"
            },
            "type": "device"
          },
          "right": {
            "decimal": 18,
            "type": "decimal"
          },
          "changesOnly": false
        },
        "type": "lessThanOrEquals"
      },
      {
        "or": [
          {
            "equals": {
              "left": {
                "device": {
                  "devices": [
                    "01caa709-9547-4bd2-b833-1aedeaa57d8d"
                  ],
                  "component": "main",
                  "capability": "switch",
                  "attribute": "switch",
                  "trigger": "Always"
                },
                "type": "device"
              },
              "right": {
                "string": "on",
                "type": "string"
              },
              "changesOnly": false
            },
            "type": "equals"
          },
          {
            "equals": {
              "left": {
                "device": {
                  "devices": [
                    "1d33051b-2218-4f82-a81b-911d6a46c9a9"
                  ],
                  "component": "main",
                  "capability": "switch",
                  "attribute": "switch",
                  "trigger": "Always"
                },
                "type": "device"
              },
              "right": {
                "string": "on",
                "type": "string"
              },
              "changesOnly": false
            },
            "type": "equals"
          }
        ],
        "type": "or"
      }
    ],
    "type": "and",
    "then": [
      {
        "notification": {
          "push": {
            "title": "Termostato, Temperatura: entre 18°C y 22°c",
            "message": "Temperature interval 18° to 22°"
          },
          "type": "push"
        },
        "type": "notification"
      }
    ],
    "sequence": {
      "then": "Parallel",
      "else": "Parallel"
    }
  },
  "type": "if"
}

So this is how it should be done also for preconditions with intervals of values and combined with other OR conditions to works fine.