Daily email with thing status and important temperatures

This is a solution to a need for a day status update on Things as well as some important temperatures.

Prerequisites:

  • Mail Binding with a SMTP thing created
  • Group for items that indicate thing status
  • Group for items that reflect important temperatures

Steps:

  1. enable your Mail Binding and add a SMTP thing. Example below will have mail:smtp:YOURSMTPTHING
  2. Create a Group named GroupStatus and add the Status Items that you wish to receive the report on.
  3. Create a Group named GroupTempReport and add the temperature Items that you wish to receive the report on.

Here is the Rule that will set the Status Item to ON or OFF based on the status of the Thing you want to track.

In this case the

  • Thing is mqtt:topic:TasmotaColdStorage
  • Item is a switch named ColdStorageStatus All items need to be Switches for this config. You could also set the item to a string to indicate “ONLINE” or “OFFLINE” but this example would need to be modified to work.
triggers:
  - id: "1"
    configuration:
      thingUID: mqtt:topic:TasmotaColdStorage
    type: core.ThingStatusChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    label: GetColdStorageStatus
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: >
        var thingStatusInfo =
        getThingStatusInfo("mqtt:topic:TasmotaColdStorage")


        if ((thingStatusInfo !== null) && (thingStatusInfo.getStatus().toString() == "ONLINE")) {
            logInfo("ThingStatus", "TasmotaColdStorage is online.")
            ColdStorageStatus.postUpdate(ON)
        } else {
            logError("ThingStatus", "TasmotaColdStorage is offline or doesn't exist.")
            ColdStorageStatus.postUpdate(OFF)
        }
    type: script.ScriptAction

Here is the Rule for the Daily Report

triggers:
  - id: "1"
    configuration:
      time: 05:00
    type: timer.TimeOfDayTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: >-
        logInfo("NrCronOut Daily0530", "Triggered")

        var String message = "\n"

        val report1 = GroupTempReport.allMembers.map[name + ": " + state.format("%s")].join("\n")

        if (! GroupStatus.allMembers.filter([state != ON]).empty) {
          val report = GroupStatus.allMembers.filter([state != ON]).map[
            name + ": " + state.format("%s")
          ].join("\n")
          message =  message + " Openhab Items Offline:\n" + report+ "\n\n" + " Openhab Temperatures:\n" + report1
        } else {
          message = message + " All items Online" + " Openhab Temperatures:\n" + report1
        }

        logInfo("Status Update:", "Message: [{}]", message)

        //getActions("mail","mail:smtp:YOURSMTPTHING").sendMail("YOUREMAIL@SOMEWHERE.COM", "OpenHAB Status Message", message)
    type: script.ScriptAction

The report will look something like this.

Openhab Items Offline:
HVACDownStairsStatus: OFF
OfficeLampStatus: OFF

Openhab Temperatures:
ColdStorage_FreezerTemperature: 26.1
ColdStorage_DeepFreezerTemperature: -3.9
ColdStorage_RefrigeratorTemperature: 34.6

A big thank you to @denominator and @Oliver2 for assisting me with getting these rules correct.

2 Likes