[Labs] Rules

@Klaus_Zeller that’s great, thanks for the update!

Looks like something has changed in the rules?
can’t create a new one:

"rules": {
    {
      "name": "Turn Screen ON",
      "condition": {
        "item": "11xveyt45581f1syghbvtxoi79.Tablet01_Screen#switch.state",
        "operator": "eq",
        "value": "on"
      },
      "action": {
        "type": "turn-on-screen"
      }
    },
    "id":{
      "name": "Turn Screen OFF",
      "condition": {
        "item": "11xveyt45581f1syghbvtxoi79.Tablet01_Screen#switch.state",
        "operator": "eq",
        "value": "off"
      },
      "action": {
        "type": "turn-off-screen",
        "binding": null,
        "value": null
      }
    }
  },

Compared to the working rule, the identifier is missing:

"rules": {
    "1rc5aavh5yvf61rucf2aaz98f7": 
    {
      "name": "Turn Screen ON",
      "condition": {

What is the correct syntax to use to create a new rule?

Each rule object should be preceded by identifier. Try this:

  "rules": {
    "rule-screen-on": {
      "name": "Turn Screen ON",
      "condition": {
        "item": "11xveyt45581f1syghbvtxoi79.Tablet01_Screen#switch.state",
        "operator": "eq",
        "value": "on"
      },
      "action": {
        "type": "turn-on-screen"
      }
    },
    "rule-screen-off": {
      "name": "Turn Screen OFF",
      "condition": {
        "item": "11xveyt45581f1syghbvtxoi79.Tablet01_Screen#switch.state",
        "operator": "eq",
        "value": "off"
      },
      "action": {
        "type": "turn-off-screen",
        "binding": null,
        "value": null
      }
    }
  },

Also, make sure there are no errors shown in the editor (red/yellow highlights) for JSON syntax. Since the config won’t be applied if there are errors.

1 Like

Yes! Thank you, it works now. I could not understand what to write here, the description says, when creating a new rule, skip the identifier.
I understand that most likely not, but I will ask :slight_smile:
Is it possible to make a change to items such as screen on, screen off, volume level when changing them from a tablet. Let me explain that the OpenHAB has a ScreenPower item, when I turn it off from the OpenHAB, the tablet screen turns off, but if you turn on the tablet with a physical button on the tablet itself, the OpenHAB will not know that the screen is on and will think that it is off. It would be cool to have some feedback.

Yeah, JSON config format change wasn’t related to the rules, so I forgot to update this post. The rules config was made to be consistent with the other components.

That feature has been on my mind quite a few times. Currently there is no good way to “bind” device behavior back to OH items, since everything is primarily designed for widget-item bindings.
So this might be added in the future, but probably not soon. If there would be a possibility to add it as Labs feature with JSON config only (similar to Rules), that might be earlier.

I’m understood, thank you!

OK, we will wait :slight_smile:

Hi! Is there a way to keep the screen on till a new rule to turn it off is activated?
From the app it’s possible with Stay Awake option. Is possible to control this setting from rules?
Thanks.

@AirmakZ Stay Awake option is required to be enabled for turn screen on/off rules to work, which would keep the screen on.

General flow of screen on/off rules is:

  • when turn-on-screen rule condition is true > turn on screen (if possible) or keep screen on
  • when turn-off-screen rule condition is true > do not keep screen on, and let Android system display timeout happen.

Both rules (screen-on/screen-off) and Stay Awake enabled are needed.

Oh!! So I misunderstood some previous comments on this feed. My understanding was that screen turn on action just send a trigger to turn on the screen but it keeps on just until android expires!
I will play with rules deeply…!
Thanks and congratulations for the application!

1 Like

@AirmakZ Sure, let me know if there are still troubles with getting it to work.

Does not work for me. Camera window opens on condition, but with a small orange text in the top left corner of the camera window with “Video format error”. Camera binding is exact the same like the Widget (copy & paste it), where it works fine if I click the Camera Widget manually. Any idea?

@anon34194377 Can you post your rule config JSON?

@igor Of course.

  "rules": {
    "camera-show": {
      "name": "Show camera",
      "condition": {
        "item": "1nxzl45wqj00j1boiubno8olid.input_boolean.garagentor#switch.state",
        "operator": "eq",
        "value": "on"
      },
      "action": {
        "type": "show-camera",
        "binding": "1nxzl45wqj00j1boiubno8olid.camera.garage#camera.video-uri",
        "value": null
      },
      "enabled": true
    },
    "camera-hide": {
      "name": "Hide camera",
      "condition": {
        "item": "1nxzl45wqj00j1boiubno8olid.input_boolean.garagentor#switch.state",
        "operator": "eq",
        "value": "off"
      },
      "action": {
        "type": "hide-camera",
        "binding": null,
        "value": null
      },
      "enabled": true
    }
  }

This is the camera widget:

              "properties": {
                "label": "",
                "video-uri": {
                  "binding": "1nxzl45wqj00j1boiubno8olid.camera.garage#camera.video-uri"
                },
                "snapshot": {
                  "binding": "1nxzl45wqj00j1boiubno8olid.camera.garage#camera.snapshot"
                },
                "snapshot-image": null,
                "snapshot-interval": "10s",
                "snapshot-timestamp": true,
                "scaling": "crop",
                "rotation": 0
              }

@anon34194377 is camera coming from Home Assistant integration?

@igor Yes, the camera is coming from Home Assistant integration (Frigate NVR).

@anon34194377 Can you check what is the state of Legacy camera streaming feature in HomeHabit Labs?

@igor Legacy camera streaming was disabled. I enabled it, but the same issue.

@anon34194377 I was actually asking if it is already enabled, because it does not apply to rule triggered camera popup (but it does apply to camera widget).
Not sure why would be any difference then, will need to check.

I also suggest disabling legacy camera streaming again, since it uses less-performant processing and will be removed in the future.

Hey @Igor, just testing out these rules to turn the screen on/off for a Lenovo tablet. I have setup a dummy light in HomeAssistant and if I add the light to a homehabit dashboard I can see it reflect the light state… Now I’m trying to turn the physical screen on/off. I think my rule looks good but not getting any result…

  "rules": {
    "screen-on": {
      "name": "Turn Screen ON",
      "condition": {
        "item": "1wlu8vob1rtcb10k8ex34u4d4t.light.dummy_light_01#light.state",
        "operator": "eq",
        "value": "on"
      },
      "action": {
        "type": "turn-on-screen"
      },
      "enabled": true
    },
    "screen-off": {
      "name": "Turn Screen OFF",
      "condition": {
        "item": "1wlu8vob1rtcb10k8ex34u4d4t.light.dummy_light_01#light.state",
        "operator": "eq",
        "value": "off"
      },
      "action": {
        "type": "turn-off-screen"
      },
      "enabled": true
    }
  }

@TommySharp For screen on/off to work, make sure that “keep awake” in Settings is enabled. Also check what is the display timeout in Android Settings, since that is the time it would take for screen to turn off after condition is satisfied.