HABApp: Handling Long Startups?

Only one member for testing purposes, but the member is part of other groups (don’t think that would matter):

{
  "members": [
    {
      "link": "http://pi-openhab:8080/rest/items/gTestGroup",
      "state": "ON",
      "type": "Switch",
      "name": "T_TestSwitchX",
      "label": "Test Switch X",
      "category": "test",
      "tags": [],
      "groupNames": [
        "gTest",
        "gTestSwitches",
        "gTestGroup"
      ]
    }
  ],
  "groupType": "Switch",
  "function": {
    "name": "AND",
    "params": [
      "ON",
      "OFF"
    ]
  },
  "link": "http://pi-openhab:8080/rest/items/gTestGroup",
  "state": "ON",
  "editable": true,
  "type": "Group",
  "name": "gTestGroup",
  "label": "Test Group",
  "category": "",
  "tags": [],
  "groupNames": []
}

None of your hooray/boo warnings work; is that about type of quotemarks?

I don’t think so… they respond as expected if I change ‘group_item’ to ‘switch_member_item’…

@alfista2600
I thought that I had pinged you, but propably not.
Please update to 0.30.1:

Groovy… thanks. I set up notifications on GitHub as well!

Does it work?

Yes! It appears to be all better now! Thanks! Starting to roll…

Quick question, do you have an example of a timer rule - for instance, one that turns on a light as a result of motion detection and then turns it off after a period of time, perhaps using parameters for how long it should stay on based on time of day? I’m sure I could cobble one together but would love to see how properly done…

and yes, I do see one in the rule examples, so I’ll work from that.

Actually, I can’t get it to compile/run with valid test items…

I changed the ‘item’ definitions to ‘SwitchItem’ but I get this error:

Cannot find reference 'SwitchItem' in '__init__.py'

I am admittedly very weak at understanding how classes work in python. Will go do some research tonight.

You have to import from HABApp.openhab.items and not from HABApp.core.items.
Also get an IDE (e.g.) PyCharm, that way you will get type hints and auto complete.

Thanks… I didn’t dig into it too far as was copy/paste from readthedocs - so I proposed a documentation change based on your advice.

I am running PyCharm (and love it!). I wish it could get info from OH like VSC.

It’s working as long as you don’t change anything :wink:

Do you get type hints and auto complete for HABApp?
If not you have to install it through settings → project interpreter and then add it to the packages.

Code complete for item names will not work though …

I do get type hints for OpenHAB, and love how it encourages me to have really clean (looking, at least) code. I’m not sure, however, how to best run/test code without checking for output in the logs just yet. I will try to figure that out.

The example linked below for a timer/motion imports ‘Item’ with I suspect was supported in an earlier version of the code, but has been deprecated?:

https://habapp.readthedocs.io/en/latest/rule_examples.html#turn-something-off-after-movement

No, it’s a locally created proxy item in HABApp to share states e.g. between rules/files (see items).

You can run HABApp on your local machine, connect to your openhab instance and use the listen_only config switch.

But tbh I hardly have the need to test my rules any more:
I separate the logic into small parts with the MultiModeItem, syntax errors are caught through PyCharm.
Most of the errors that remain are complex logic errors that are not easy to catch through test cases.

And if there are errors I get a notification through Pushover directly on my mobile phone so I don’t have to look at the logs.

Oh, right! My bad… I can’t help but look at this through an OpenHAB lens. I need to think about how that other non-OH-related functionality can be leveraged for me.

And yes, now that I am getting rolling, I’m not sure I really need more debugging capability. I found DSL rules so difficult to troubleshoot but I’m very happy with HABApp (again, great work!).

Now I need to look at MultiModeItems as I think that might solve a question I was going to ask.

When coding, I learn best by finding examples that are close to my needs and modifying them. I have a hard time reading a manual without seeing the code in action. Thanks for your patience and support.

@alfista2600
Check out the new HABApp version 0.30.2.
I included a small fix which should make startup more robust so you shouldn’t get the error messages again.
Additionally there is a command line argument which will make HABApp wait until the specified os uptime before it connects.

2 Likes

Cool - upgrading now!

1 Like

Have you noticed an improvement in the error handling?
Would you mind posting the log where HABApp connects for the first time?

Sure - I’ll do a reboot later today or tomorrow (things are a bit crazy now) and post the logs…

No worries - just so I can wrap it up and see if there is more that I need to do

Other than all my coding errors, it looks like it is waiting to connect more gracefully!

2021-06-02 09:01:46.706 [WARN ] [HABApp.openhab.connection           ] - "Cannot connect to host localhost:8080 ssl:default [Connect call failed ('127.0.0.1', 8080)]" (<class 'aiohttp.client_exceptions.ClientConnectorError'>)
2021-06-02 09:01:47.720 [WARN ] [HABApp.openhab.connection           ] - "Cannot connect to host localhost:8080 ssl:default [Connect call failed ('::1', 8080, 0, 0)]" (<class 'aiohttp.client_exceptions.ClientConnectorError'>)
2021-06-02 09:01:49.732 [WARN ] [HABApp.openhab.connection           ] - "Cannot connect to host localhost:8080 ssl:default [Connect call failed ('127.0.0.1', 8080)]" (<class 'aiohttp.client_exceptions.ClientConnectorError'>)
2021-06-02 09:01:53.746 [WARN ] [HABApp.openhab.connection           ] - "Cannot connect to host localhost:8080 ssl:default [Connect call failed ('::1', 8080, 0, 0)]" (<class 'aiohttp.client_exceptions.ClientConnectorError'>)
2021-06-02 09:02:01.766 [WARN ] [HABApp.openhab.connection           ] - "Cannot connect to host localhost:8080 ssl:default [Connect call failed ('127.0.0.1', 8080)]" (<class 'aiohttp.client_exceptions.ClientConnectorError'>)
2021-06-02 09:02:17.786 [WARN ] [HABApp.openhab.connection           ] - "Cannot connect to host localhost:8080 ssl:default [Connect call failed ('127.0.0.1', 8080)]" (<class 'aiohttp.client_exceptions.ClientConnectorError'>)
2021-06-02 09:02:52.489 [WARN ] [HABApp.openhab.connection           ] - Disconnected! Expected success but got status 404 for /rest/things/
2021-06-02 09:02:55.298 [WARN ] [HABApp.Rules                        ] - Found no instances of HABApp.Rule in /etc/openhab/habapp/rules/admin/assign_metadata.py
2021-06-02 09:02:55.303 [WARN ] [HABApp.Rules                        ] - Found no instances of HABApp.Rule in /etc/openhab/habapp/rules/admin/create_tasmota.py
2021-06-02 09:02:55.479 [WARN ] [HABApp.Rules                        ] - Found no instances of HABApp.Rule in /etc/openhab/habapp/rules/test/log-test.py
1 Like