GithubHelp home page GithubHelp logo

spacemanspiff2007 / habapp Goto Github PK

View Code? Open in Web Editor NEW
53.0 53.0 23.0 3.43 MB

Easy home automation with MQTT and/or openHAB

License: Apache License 2.0

Python 99.84% Dockerfile 0.09% Shell 0.07%
home-automation mqtt openhab pypi python

habapp's People

Contributors

jhk avatar spacemanspiff2007 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

habapp's Issues

Logging does not rotate logs

I think I have a problem with my logging.yml file.

My rules log file stops logging when it reaches 100000000 instead or rotating to a new log file.

This is the log file:

-rw-r--r-- 1 openhab openhab  3428555 Oct  1 08:10 HABAppevents.log
-rw-r--r-- 1 openhab openhab 10485632 Oct  1 08:01 HABAppevents.log.1
-rw-r--r-- 1 openhab openhab 10485757 Oct  1 07:32 HABAppevents.log.2
-rw-r--r-- 1 openhab openhab 10485683 Oct  1 07:03 HABAppevents.log.3
-rw-r--r-- 1 openhab openhab     1393 Oct  1 01:56 HABApp.log
-rw-r--r-- 1 openhab openhab  9999986 Sep 30 17:49 HABApprules.log

As you can see HABAppevents.log rotates as expected, but HABApprules.log does not.
This is my logging.yml file:

version : 1

formatters:
  HABApp_format:
          format: '[%(asctime)s] [%(name)26s] %(levelname)8s | %(funcName)19s: %(message)s'

handlers:
  HABApp_default:
    class: logging.handlers.RotatingFileHandler
    filename: 'HABApp.log'
    maxBytes: 10_485_760
    backupCount: '3'

    formatter: HABApp_format
    level: DEBUG

  EventFile:
    class: logging.handlers.RotatingFileHandler
    filename: 'HABAppevents.log'
    maxBytes: 10_485_760
    backupCount: 3

    formatter: HABApp_format
    level: DEBUG

  BufferEventFile:
    class: logging.handlers.MemoryHandler
    capacity: 10
    formatter: HABApp_format
    target: EventFile
    level: DEBUG

  MyRuleHandler:
    class: logging.handlers.RotatingFileHandler
    filename: 'HABApprules.log'    # absolute filename is recommended
    maxBytes: 10_000_000
    backupCount: '3'

    formatter: HABApp_format  # use the specified formatter (see above)
    level: DEBUG

  BufferRuletFile:
    class: logging.handlers.MemoryHandler
    capacity: 10
    formatter: HABApp_format
    target: MyRuleHandler
    level: DEBUG


loggers:
  HABApp:
    level: DEBUG
    handlers:
      - HABApp_default
    propagate: False

  HABApp.EventBus:
    level: INFO
    handlers:
      - BufferEventFile
    propagate: False

  MyRule:
    level: DEBUG
    handlers:
      - BufferRuletFile
    propagate: False

Can you tell me what I've got wrong? I've tried without the BufferRuletFile as well, and that does the same thing.

Thanks.

V0.10.0 Warning

Thanks for all the updates in V0.10.

I am now getting this warning in the logs:

[2019-11-01 15:25:52,396] [               HABApp.Rule]WARNING| send_warnings_to_log: /usr/local/lib/python3.6/dist-packages/paho/mqtt/client.py:1571: ResourceWarning:unclosed <ssl.SSLSocket fd=17, family=AddressFamily.AF_INET6, type=2049, proto=6, laddr=('::1', 32907, 0, 0)>

I'm not actually using mqtt in my rules at the moment, but I do have my mqtt server configured in config.yml

Any idea what is causing this?

OK, I think it was my TLS settings. seems to have gone away when I disabled TLS.

Timezone settings for main log and events

Hi!

The timestamps of the main log (HABApp.log) seems to use UTC, correct?
Is there a possibility to specify a timezone for this? I am in CEST (+0200) right now.

What does the current (only?) timezone setting in openhab->general do exactly?
Does it modify values from DateTime items or is it used for modifying the event log timestamps?

Items with unit set

Items with the unit property set don't get converted to the proper python type

Hue Lights Error

Got the following error when turning on some Hue lights:


[2019-09-28 01:51:49,395] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: '>' not supported between instances of 'str' and 'float'
[2019-09-28 01:51:49,396] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Traceback (most recent call last):
[2019-09-28 01:51:49,396] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 120, in on_sse_event
[2019-09-28 01:51:49,396] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     HABApp.core.Items.get_item(event.name).set_state(event.value)
[2019-09-28 01:51:49,397] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/core/items/item_color.py", line 27, in set_state
[2019-09-28 01:51:49,397] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     self.hue = min(max(0.0, hue), HUE_FACTOR)
[2019-09-28 01:51:49,397] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: TypeError: '>' not supported between instances of 'str' and 'float'

Monitor ThingStatusInfoEvent to check if thing is ONLINE or not

This is a suggestion.

I ran into a problem where I needed to check the status of a Thing ie ONLINE or OFFLINE.

In OH rules, you can do this like this:

rule "TV Binding State Changed"
when
    Thing "samsungtv:tv:familyroom" changed
then
    var status = getThingStatusInfo("samsungtv:tv:familyroom").getStatus()
    logInfo("Family Room TV", "TV Thing status changed to: " + status)
    postUpdate(TV_Status, status.toString)
end

Which just updates an Item when the status of a Thing changes.
Looking at your class HttpConnection it is fairly simple to add smarthome/things/ to the list of SSE items monitored.

I hacked up a quick test, and the thing status updates look like this:

on_sse_event: events: {'topic': 'smarthome/things/chromecast:chromecast:32c788dcb32176c97ca3c49c94929a42/status', 'payload': '{"status":"ONLINE","statusDetail":"NONE"}', 'type': 'ThingStatusInfoEvent'}

The one I'm looking for is:

on_sse_event: events: {'topic': 'smarthome/things/samsungtv:tv:familyroom/statuschanged', 'payload': '[{"status":"ONLINE","statusDetail":"NONE"},{"status":"OFFLINE","statusDetail":"NONE"}]', 'type': 'ThingStatusInfoChangedEvent'}
on_sse_event: events: {'topic': 'smarthome/things/samsungtv:tv:familyroom/status', 'payload': '{"status":"ONLINE","statusDetail":"NONE"}', 'type': 'ThingStatusInfoEvent'}

You also get ThingUpdatedEvent and a bunch of others for each channel. Some of the events are quite long (zwave events for instance), but this gives the possibility of checking if something is online or not.

It might be wothwhile to trap certain events ThingStatusInfoChangedEvent and ThingStatusInfoEvent possibly others, as a way to check the status of Things as well as items.

As I say, just a suggestion.

[REQ] Group features

Hi!

I use a lot of looping through groups to do different things, would be very nice to get some builtin functions for this 😄
Like:
for myItem in myGroup:
// do stuff

if (myItem.isMemberOf('MyGroup')) // Check if item is in MyGroup

for groups in myItem['groupNames'] // Loop through an items groups

also if there's a possibity to get the triggering item in a group change/update (listen) event 😇

V12 issues MQTT errors

Updated to V12. and started getting a lot of MQTT errors:

2020-01-20 12:06:21,751[                    HABApp]ERROR| __process_exception: Error 'utf-8' codec can't decode byte 0xbc in position 0: invalid start byte in process_msg:
2020-01-20 12:06:21,752[                    HABApp]ERROR| __process_exception: Traceback (most recent call last):
2020-01-20 12:06:21,753[                    HABApp]ERROR| __process_exception:   File "/home/nick/Scripts/HABApp/HABApp/mqtt/mqtt_connection.py", line 129, in process_msg
2020-01-20 12:06:21,753[                    HABApp]ERROR| __process_exception:     payload = message.payload.decode("utf-8")

This is with the subscribe topic set to '#'. I have a lot of mqtt messages, and it seems that some of them do not decode as unicode (some are binary).

I changed the subscribe string to '/OH2/#' which has no messages being sent to it, and this resolved the error messages.

Just mentioning this as anyone that subscribes to everything, but sends non-text mqtt messages will get a lot of errors logged.

Event errors

Seeing a bunch of these error too. I'll try to look the items up and post later:

[2019-09-28 10:26:47,248] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     raise ValueError(f'Invalid value for SwitchItem {self.name}: {new_state}')
[2019-09-28 10:26:47,248] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: ValueError: Invalid value for SwitchItem HSM200LightControlStatus3: 0
[2019-09-28 10:26:47,251] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Invalid value for SwitchItem HSM200LightControlStatus5: 1
[2019-09-28 10:26:47,251] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Traceback (most recent call last):
[2019-09-28 10:26:47,252] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 120, in on_sse_event
[2019-09-28 10:26:47,252] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     HABApp.core.Items.get_item(event.name).set_state(event.value)
[2019-09-28 10:26:47,252] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/items/switch_item.py", line 11, in set_state
[2019-09-28 10:26:47,252] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     raise ValueError(f'Invalid value for SwitchItem {self.name}: {new_state}')
[2019-09-28 10:26:47,253] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: ValueError: Invalid value for SwitchItem HSM200LightControlStatus5: 1
[2019-09-28 10:26:51,539] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Invalid value for SwitchItem HSM200LightControlStatus3: 1
[2019-09-28 10:26:51,540] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Traceback (most recent call last):
[2019-09-28 10:26:51,540] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 120, in on_sse_event
[2019-09-28 10:26:51,540] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     HABApp.core.Items.get_item(event.name).set_state(event.value)
[2019-09-28 10:26:51,540] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/items/switch_item.py", line 11, in set_state
[2019-09-28 10:26:51,541] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     raise ValueError(f'Invalid value for SwitchItem {self.name}: {new_state}')
[2019-09-28 10:26:51,541] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: ValueError: Invalid value for SwitchItem HSM200LightControlStatus3: 1
[2019-09-28 10:26:51,548] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Invalid value for SwitchItem HSM200LightControlStatus5: 0
[2019-09-28 10:26:51,549] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Traceback (most recent call last):
[2019-09-28 10:26:51,549] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 120, in on_sse_event
[2019-09-28 10:26:51,549] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     HABApp.core.Items.get_item(event.name).set_state(event.value)
[2019-09-28 10:26:51,549] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/items/switch_item.py", line 11, in set_state
[2019-09-28 10:26:51,550] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     raise ValueError(f'Invalid value for SwitchItem {self.name}: {new_state}')
[2019-09-28 10:26:51,550] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: ValueError: Invalid value for SwitchItem HSM200LightControlStatus5: 0
[2019-09-28 10:32:41,394] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Invalid value for SwitchItem HSM200LightControlStatus5: 1
[2019-09-28 10:32:41,395] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Traceback (most recent call last):
[2019-09-28 10:32:41,395] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 120, in on_sse_event
[2019-09-28 10:32:41,395] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     HABApp.core.Items.get_item(event.name).set_state(event.value)
[2019-09-28 10:32:41,395] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/items/switch_item.py", line 11, in set_state
[2019-09-28 10:32:41,396] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     raise ValueError(f'Invalid value for SwitchItem {self.name}: {new_state}')
[2019-09-28 10:32:41,396] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: ValueError: Invalid value for SwitchItem HSM200LightControlStatus5: 1
[2019-09-28 10:32:41,403] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Invalid value for SwitchItem HSM200LightControlStatus3: 0
[2019-09-28 10:32:41,404] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Traceback (most recent call last):
[2019-09-28 10:32:41,404] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 120, in on_sse_event
[2019-09-28 10:32:41,404] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     HABApp.core.Items.get_item(event.name).set_state(event.value)
[2019-09-28 10:32:41,404] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/items/switch_item.py", line 11, in set_state
[2019-09-28 10:32:41,405] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     raise ValueError(f'Invalid value for SwitchItem {self.name}: {new_state}')
[2019-09-28 10:32:41,405] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: ValueError: Invalid value for SwitchItem HSM200LightControlStatus3: 0
[2019-09-28 10:32:45,598] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Invalid value for SwitchItem HSM200LightControlStatus3: 1
[2019-09-28 10:32:45,599] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Traceback (most recent call last):
[2019-09-28 10:32:45,599] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 120, in on_sse_event
[2019-09-28 10:32:45,599] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     HABApp.core.Items.get_item(event.name).set_state(event.value)
[2019-09-28 10:32:45,599] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/items/switch_item.py", line 11, in set_state
[2019-09-28 10:32:45,600] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     raise ValueError(f'Invalid value for SwitchItem {self.name}: {new_state}')
[2019-09-28 10:32:45,600] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: ValueError: Invalid value for SwitchItem HSM200LightControlStatus3: 1
[2019-09-28 10:32:45,603] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Invalid value for SwitchItem HSM200LightControlStatus5: 0
[2019-09-28 10:32:45,603] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Traceback (most recent call last):
[2019-09-28 10:32:45,604] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 120, in on_sse_event
[2019-09-28 10:32:45,604] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     HABApp.core.Items.get_item(event.name).set_state(event.value)
[2019-09-28 10:32:45,604] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/items/switch_item.py", line 11, in set_state
[2019-09-28 10:32:45,604] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     raise ValueError(f'Invalid value for SwitchItem {self.name}: {new_state}')
[2019-09-28 10:32:45,605] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: ValueError: Invalid value for SwitchItem HSM200LightControlStatus5: 0
[2019-09-28 10:37:48,623] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Invalid value for SwitchItem DoorTriggers1Status1: 0
[2019-09-28 10:37:48,624] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Traceback (most recent call last):
[2019-09-28 10:37:48,625] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 120, in on_sse_event
[2019-09-28 10:37:48,625] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     HABApp.core.Items.get_item(event.name).set_state(event.value)
[2019-09-28 10:37:48,625] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/items/switch_item.py", line 11, in set_state
[2019-09-28 10:37:48,625] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     raise ValueError(f'Invalid value for SwitchItem {self.name}: {new_state}')
[2019-09-28 10:37:48,626] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: ValueError: Invalid value for SwitchItem DoorTriggers1Status1: 0
[2019-09-28 10:37:48,629] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Invalid value for SwitchItem DoorTriggers1Status2: 1
[2019-09-28 10:37:48,630] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Traceback (most recent call last):
[2019-09-28 10:37:48,630] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 120, in on_sse_event
[2019-09-28 10:37:48,630] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     HABApp.core.Items.get_item(event.name).set_state(event.value)
[2019-09-28 10:37:48,631] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/items/switch_item.py", line 11, in set_state
[2019-09-28 10:37:48,631] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     raise ValueError(f'Invalid value for SwitchItem {self.name}: {new_state}')
[2019-09-28 10:37:48,631] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: ValueError: Invalid value for SwitchItem DoorTriggers1Status2: 1
[2019-09-28 10:37:48,863] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Invalid value for SwitchItem HSM200LightControlStatus3: 0
[2019-09-28 10:37:48,864] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Traceback (most recent call last):
[2019-09-28 10:37:48,864] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 120, in on_sse_event
[2019-09-28 10:37:48,865] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     HABApp.core.Items.get_item(event.name).set_state(event.value)
[2019-09-28 10:37:48,866] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/items/switch_item.py", line 11, in set_state
[2019-09-28 10:37:48,866] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     raise ValueError(f'Invalid value for SwitchItem {self.name}: {new_state}')
[2019-09-28 10:37:48,867] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: ValueError: Invalid value for SwitchItem HSM200LightControlStatus3: 0
[2019-09-28 10:37:48,870] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Invalid value for SwitchItem HSM200LightControlStatus4: 1
[2019-09-28 10:37:48,871] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: Traceback (most recent call last):
[2019-09-28 10:37:48,871] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 120, in on_sse_event
[2019-09-28 10:37:48,871] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     HABApp.core.Items.get_item(event.name).set_state(event.value)
[2019-09-28 10:37:48,871] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/items/switch_item.py", line 11, in set_state
[2019-09-28 10:37:48,872] [ HABApp.openhab.Connection]    ERROR |        on_sse_event:     raise ValueError(f'Invalid value for SwitchItem {self.name}: {new_state}')
[2019-09-28 10:37:48,872] [ HABApp.openhab.Connection]    ERROR |        on_sse_event: ValueError: Invalid value for SwitchItem HSM200LightControlStatus4: 1

OK, Here are the items:

Switch   HSM200LightControlStatus1 "HSM200 Light Control Status 1" (GDevices,GRoom2) {mios="unit:Home,device:42/service/MSwitch1/Status1"}
Switch   HSM200LightControlStatus2 "HSM200 Light Control Status 2" (GDevices,GRoom2) {mios="unit:Home,device:42/service/MSwitch1/Status2"}
Switch   HSM200LightControlStatus3 "HSM200 Light Control Status 3" (GDevices,GRoom2) {mios="unit:Home,device:42/service/MSwitch1/Status3"}
Switch   HSM200LightControlStatus4 "HSM200 Light Control Status 4" (GDevices,GRoom2) {mios="unit:Home,device:42/service/MSwitch1/Status4"}
Switch   HSM200LightControlStatus5 "HSM200 Light Control Status 5" (GDevices,GRoom2) {mios="unit:Home,device:42/service/MSwitch1/Status5"}
Switch   HSM200LightControlStatus6 "HSM200 Light Control Status 6" (GDevices,GRoom2) {mios="unit:Home,device:42/service/MSwitch1/Status6"}
Switch   HSM200LightControlStatus7 "HSM200 Light Control Status 7" (GDevices,GRoom2) {mios="unit:Home,device:42/service/MSwitch1/Status7"}
Switch   HSM200LightControlStatus8 "HSM200 Light Control Status 8" (GDevices,GRoom2) {mios="unit:Home,device:42/service/MSwitch1/Status8"}

and

Switch   DoorTriggers2Status1 "Door Triggers 2 Status 1" (GDevices) {mios="unit:Home,device:37/service/MSwitch1/Status1"}
Switch   DoorTriggers2Status2 "Door Triggers 2 Status 2" (GDevices) {mios="unit:Home,device:37/service/MSwitch1/Status2"}
Switch   DoorTriggers2Status3 "Door Triggers 2 Status 3" (GDevices) {mios="unit:Home,device:37/service/MSwitch1/Status3"}
Switch   DoorTriggers2Status4 "Door Triggers 2 Status 4" (GDevices) {mios="unit:Home,device:37/service/MSwitch1/Status4"}
Switch   DoorTriggers2Status5 "Door Triggers 2 Status 5" (GDevices) {mios="unit:Home,device:37/service/MSwitch1/Status5"}
Switch   DoorTriggers2Status6 "Door Triggers 2 Status 6" (GDevices) {mios="unit:Home,device:37/service/MSwitch1/Status6"}
Switch   DoorTriggers2Status7 "Door Triggers 2 Status 7" (GDevices) {mios="unit:Home,device:37/service/MSwitch1/Status7"}
Switch   DoorTriggers2Status8 "Door Triggers 2 Status 8" (GDevices) {mios="unit:Home,device:37/service/MSwitch1/Status8"}

These are all coming from a Vera Edge via the mios binding, from Zwave devices.

BTW, I'm not saying there is anything wrong with your great library, my OH installation has grown over the years, and there is some weird convoluted stuff in there.

These items were added to vera, because OH (1.8 I think) didn't support SECURITY or the COLOR command.

fix typo in groupNames and groupType

Currently creating items does not put them in the correct group.
groupNames is lowercase!

[
  {
    "type": "string",
    "name": "string",
    "label": "string",
    "category": "string",
    "tags": [
      "string"
    ],
    "groupNames": [
      "string"
    ],
    "groupType": "string",
    "function": {
      "name": "string",
      "params": [
        "string"
      ]
    }
  }
]

ujson package does not compile on Windows

  Running setup.py install for ujson ... error
    ERROR: Complete output from command 'C:\Users\User\Desktop\HABapp\habapp\Scripts\python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\\Users\\User\\AppData\\Local\\Temp\\pip-install-4y0tobjp\\ujson\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\User\AppData\Local\Temp\pip-record-6t2yo712\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\User\Desktop\HABapp\habapp\include\site\python3.7\ujson':
    ERROR: Warning: 'classifiers' should be a list, got type 'filter'
    running install
    running build
    running build_ext
    building 'ujson' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/
    ----------------------------------------
ERROR: Command "'C:\Users\User\Desktop\HABapp\habapp\Scripts\python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\\Users\\User\\AppData\\Local\\Temp\\pip-install-4y0tobjp\\ujson\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\User\AppData\Local\Temp\pip-record-6t2yo712\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\User\Desktop\HABapp\habapp\include\site\python3.7\ujson'" failed with error code 1 in C:\Users\User\AppData\Local\Temp\pip-install-4y0tobjp\ujson\

Workaround:
https://www.scivision.dev/python-windows-visual-c-14-required/

V 0.10.0 log.warn method is depreciated

I'm getting this message in the logs now:

[2019-11-01 16:20:02,479] [               HABApp.Rule]WARNING| send_warnings_to_log: /etc/openhab2/HABApp/lib/utils.py:103: DeprecationWarning:The 'warn' method is deprecated, use 'warning' instead

It doesn't say what this refers to, but I'm assuming its the standard log method log.warn as I think this is the only place I'm using warn for anything.

Why depreciate a standard log method? warn or warning can be used interchangeably in the logging module. This warning should be removed, it's not valid and is filling up my log files.

I have to say the number of things that have been depreciated are causing a huge amount of work to update all my files. This is one of the reasons for moving from the OH2 rules engine, the continual depreciation warnings are such a pain. Please don't fall down this rabbit hole.

Thanks.

Docker support

Hi!
Do you have any plans for a dockerized version of HABapp?

Ping not working

I have enabled ping in the config file and setup the item in openhab, but the value never gets updated. I found the function async_ping in the code but I couldn't find it being called from anywhere. Is that the issue?

I have a simple rule up and running and it gets triggered, so the system works. I am running habapp in a docker container.

If Rule is edited, get multiple instances of rule running

I may be wrong, but it seems if I edit a rule, and save it, then I end up with multiple instances of the rule running.

If i restart HABApp, then everything is OK.

I noticed this, when I'm using

self.listen_event('HEM_P', self.item_value_changed, ValueChangeEvent)

I edited and saved the rule, then I started getting two messages in the log file, for the same event.

It doesn't do it every time, only if I make a major change in the file (like delete an rule, or add a listener).

Also, is there any difference between ItemStateChangedEvent and ValueChangeEvent? I seem to get two triggers for ValueChangeEvent sometimes, but only one for ItemStateChangedEvent (but this could just be part of the same issue described above).

I'm still learning how to use your library, so I'm revising rules a lot, and this seems to become an issue (fixed by a restart so not a huge deal).

I have three rules files currently, could this be part of the issue?

Thanks,

Files get unloaded/loaded 4 times on file save

I know you fixed the issue of files being loaded multiple times on one change, but the new code now causes files to be unloaded/loaded multiple times for each save. So unloads matches loads, but it's still more than once for every save event.

The new methods are also a little less logical..

I have re-written the unload and load routines as below, as a proposed solution.. I think they are easier to understand as well.

    @PrintException
    def request_file_unload(self, event: HABApp.core.events.habapp_events.RequestFileUnloadEvent):
        path = event.get_path(self.runtime.config.directories.rules)
        path_str = str(path)

        try:
            if self.__load_lock.locked():
                return None
            else:
                with self.__load_lock:
                    # Only unload already loaded files
                    already_loaded = path_str in self.files
                    if not already_loaded:
                        log.warning(f'Rule file {path} is not yet loaded and therefore can not be unloaded')
                        return None
                    with self.__files_lock:
                        log.debug(f'Removing file: {path}')
                        rule = self.files.pop(path_str)
                    rule.unload()
        except Exception:
            log.error(f"Could not remove {path}!")
            for l in traceback.format_exc().splitlines():
                log.error(l)
            return None

    @PrintException
    def request_file_load(self, event: HABApp.core.events.habapp_events.RequestFileLoadEvent):

        path = event.get_path(self.runtime.config.directories.rules)
        path_str = str(path)

        # Only load existing files
        if not path.is_file():
            log.warning(f'Rule file {path} does not exist and can not be loaded!')
            return None

        try:
            # Unload if we have already loaded
            already_loaded = path_str in self.files
            if already_loaded:
                self.request_file_unload(event)
                
            # serialize loading    
            if self.__load_lock.locked():
                return None 
            else:    
                with self.__load_lock:
                    log.debug(f'Loading file: {path}')
                    with self.__files_lock:
                        self.files[path_str] = file = RuleFile(self, path)
                    file.load()
        except Exception:
            log.error(f"Could not (fully) load {path}!")
            for l in traceback.format_exc().splitlines():
                log.error(l)
            return None

        log.debug(f'File {path_str} successfully loaded!')

        # Do simple checks which prevent errors
        file.check_all_rules()

It does keep the logs cleaner as well, instead of having multiple unload/load events.

Support Things

Support Thing types from openhab.

  • query values initially on connect
  • Create class which holds the properties
  • add REST API to read/set values and properties
  • add documentation

Fix crash for empty working dir

Traceback (most recent call last):
  File "/opt/habapp/lib/python3.6/site-packages/HABApp/__main__.py", line 117, in main
    app.load_config(config_folder=find_config_folder(args.config))
  File "/opt/habapp/lib/python3.6/site-packages/HABApp/__main__.py", line 20, in find_config_folder
    working_dir.with_name('HABApp'),            # current working dir
  File "/usr/lib/python3.6/pathlib.py", line 817, in with_name
    raise ValueError("%r has an empty name" % (self,))
ValueError: PosixPath('/') has an empty name
PosixPath('/') has an empty name
PosixPath('/') has an empty name

Cant use item state in ItemCommandEvent Reliably

This isn't really a bug, but it highlights an error in your "example rule".

Fortunately I am familiar with this issue in normal OH rules, so it was easy to figure out the problem. For the unwary, this is a horrible trap though.

Here is my test rule, based on your example rule:

class TestRule(HABApp.Rule):

    def __init__(self):
        super().__init__()

        # Trigger on item updates
        self.listen_event( 'test', self.item_state_update, ItemStateEvent)
        self.listen_event( 'test', self.item_state_update, ValueUpdateEvent)

        # Trigger on item changes
        #self.listen_event( 'test', self.item_state_change, ItemStateChangedEvent)
        #self.listen_event( 'test', self.item_state_change, ValueChangeEvent)

        # Trigger on item commands
        self.listen_event( 'test', self.item_command, ItemCommandEvent)

    def item_state_update(self, event):
        assert isinstance(event, ValueUpdateEvent)
        log.debug( f'{event}')
        switch_item = self.get_item('test')
        log.info('item_state_update: Switch state is %s' % switch_item)
        if switch_item.is_on():
            log.info( 'item_state_update: Switch is ON')
        if switch_item.is_off():
            log.info( 'item_state_update: Switch is OFF')

    def item_state_change(self, event):
        assert isinstance(event, ValueChangeEvent)
        log.debug( f'{event}')

        # interaction is available through self.openhab or self.oh
        #self.openhab.send_command('TestItemCommand', 'ON')

    def item_command(self, event):
        assert isinstance(event, ItemCommandEvent)
        log.debug( f'{event}')

        # interaction is available through self.openhab or self.oh
        #self.oh.post_update('TestItemUpdate', 123)

        # example for interaction with openhab item type
        switch_item = self.get_item('test')
        assert isinstance(switch_item, SwitchItem)
        log.info('item_command: Item %s received command %s' % (event.name, event.value))
        log.info('item_command: Switch state is %s' % switch_item)
        if switch_item.is_on():
            log.info( 'item_command: Switch is ON')
        if switch_item.is_off():
            log.info( 'item_command: Switch is OFF')
        #    switch_item.off()

Here is the output from my rules.log file when test switch is turned on from the UI

[2019-09-27 11:31:27,845] [                   MyRule]    DEBUG | <ItemCommandEvent name: test, value: ON>
[2019-09-27 11:31:27,845] [                   MyRule]     INFO | item_command: Switch state is OFF
[2019-09-27 11:31:27,846] [                   MyRule]     INFO | item_command: test received command ON
[2019-09-27 11:31:27,846] [                   MyRule]     INFO | item_command: Switch is OFF
[2019-09-27 11:31:27,851] [                   MyRule]    DEBUG | <ItemStateEvent name: test, value: ON>
[2019-09-27 11:31:27,851] [                   MyRule]     INFO | item_state_update: Switch state is ON
[2019-09-27 11:31:27,852] [                   MyRule]    DEBUG | <ItemStateEvent name: test, value: ON>
[2019-09-27 11:31:27,852] [                   MyRule]     INFO | item_state_update: Switch is ON
[2019-09-27 11:31:27,854] [                   MyRule]     INFO | item_state_update: Switch state is ON
[2019-09-27 11:31:27,855] [                   MyRule]     INFO | item_state_update: Switch is ON

If you look closely at the ouput from the item_command routine, you can see that the switch state is reported as OFF, even though the command was ON. You get the same result from switch_item.is_on() and switch_item.is_off() ie they are backwards.

This is because the command ON was received, but the state of the switch has not changed yet. This is why you have to use ReceivedCommand in normal OH rules (in HABApp event.value). It means that you can't use the state of the item that triggered the rule in a "received command" rule, as the state may not have been updated yet, you can only use the state of other Items - not the one that triggered the rule. The same applies to the is_on() and is_off() methods.

I am pointing this out, because your example rule using 'TestSwitch' is super confusing in this respect, and is incorrectly using is_on() in item_command.

Having said that, this library looks like it will be really useful in sorting out my mess of OH rules. of which I have several hundred. I will try moving some over, and see how it goes.

Thanks for the hard work!

How to get members of a Group?

I have several rules that look like this:

    // all lights in group bedtime to OFF, with 100 ms Delay
    bedtime?.members.forEach[ item,i|createTimer(now.plusMillis(i*100)) [ sendCommand(item, OFF) ] ]

So I need to iterate over the members of the group. It I try to use the group name bedtime using get_item, I just get an item with no value and no members.

I can't figure out how groups are handled in the code. It looks like members is broken out, but the final group ends up as a regular Item, not a Group item.

Can you give some pointers on how to access the members of a group? or how to tell what group an item is a member of?

Or are groups not completely implemented yet?

Thanks.

Refactor loading of rules

  File "/opt/habapp/lib/python3.6/site-packages/HABApp/rule_manager/rule_manager.py", line 68, in process_scheduled_events
    for rule in file.iterrules():
  File "/opt/habapp/lib/python3.6/site-packages/HABApp/rule_manager/rule_file.py", line 43, in iterrules
    for rule in self.rules.values():
RuntimeError: dictionary changed size during iteration

V12 release notes confusion

In the V12 release notes you say that

  • Removed ValueChangeEvent & ValueUpdateEvent

But these are still present (removed them anyway from my rules as I assume you intend to remove them), but ValueNoUpdateEvent has been removed and is not mentioned.

I replaced ValueNoUpdateEvent with ItemNoUpdateEvent using the new Item.watch_update() syntax.

I'm hoping this will work.

SSE request Error: Unknown Event: GroupItemStateChangedEvent

I have seen this in the logs:

[2019-04-19 09:27:09,556] [                   HABApp]     INFO | HABApp Version 0.4.0
[2019-04-19 09:27:09,556] [   HABApp.mqtt.connection]     INFO | MQTT disabled
[2019-04-19 09:27:09,558] [    HABApp.RuleParameters]     INFO | Parameter files disabled. Folder /config/param does not exist!
[2019-04-19 09:27:09,587] [HABApp.openhab.connection]     INFO | Connected to OpenHAB instance 5b13f244-c394-47c1-aa36-3eec75f368ee
[2019-04-19 09:27:09,645] [HABApp.openhab.Connection]     INFO | Updated 154 items
[2019-04-19 09:27:15,066] [             HABApp.Rules]     INFO | Added rule "MyRule" from time_rule.py
[2019-04-19 09:27:15,567] [             HABApp.Rules]     INFO | Added rule "MyOpenhabRule" from openhab_rule.py
[2019-04-19 09:27:15,568] [              HABApp.Rule]  WARNING | Item "TestContact" does not exist (yet)! self.listen_event in "MyOpenhabRule" may not work as intended.
[2019-04-19 09:27:15,568] [              HABApp.Rule]  WARNING | Item "TestDateTime" does not exist (yet)! self.listen_event in "MyOpenhabRule" may not work as intended.
[2019-04-19 09:27:15,568] [              HABApp.Rule]  WARNING | Item "TestDateTime" does not exist (yet)! self.listen_event in "MyOpenhabRule" may not work as intended.
[2019-04-19 09:27:15,568] [              HABApp.Rule]  WARNING | Item "TestSwitch" does not exist (yet)! self.listen_event in "MyOpenhabRule" may not work as intended.
[2019-04-19 09:27:15,568] [              HABApp.Rule]  WARNING | Item "TestSwitch" does not exist (yet)! self.listen_event in "MyOpenhabRule" may not work as intended.
[2019-04-19 09:27:44,188] [HABApp.openhab.connection]    ERROR | SSE request Error: Unknown Event: GroupItemStateChangedEvent
[2019-04-19 09:27:44,189] [HABApp.openhab.connection]    ERROR | Traceback (most recent call last):
[2019-04-19 09:27:44,189] [HABApp.openhab.connection]    ERROR |   File "/usr/local/lib/python3.7/site-packages/HABApp/openhab/events/__init__.py", line 14, in get_event
[2019-04-19 09:27:44,190] [HABApp.openhab.connection]    ERROR |     return __event_lookup[event_type](_in_dict)
[2019-04-19 09:27:44,190] [HABApp.openhab.connection]    ERROR | KeyError: 'GroupItemStateChangedEvent'
[2019-04-19 09:27:44,190] [HABApp.openhab.connection]    ERROR | 
[2019-04-19 09:27:44,190] [HABApp.openhab.connection]    ERROR | During handling of the above exception, another exception occurred:
[2019-04-19 09:27:44,190] [HABApp.openhab.connection]    ERROR | 
[2019-04-19 09:27:44,190] [HABApp.openhab.connection]    ERROR | Traceback (most recent call last):
[2019-04-19 09:27:44,191] [HABApp.openhab.connection]    ERROR |   File "/usr/local/lib/python3.7/site-packages/HABApp/openhab/http_connection.py", line 198, in async_process_sse_events
[2019-04-19 09:27:44,191] [HABApp.openhab.connection]    ERROR |     call(event)
[2019-04-19 09:27:44,191] [HABApp.openhab.connection]    ERROR |   File "/usr/local/lib/python3.7/site-packages/HABApp/openhab/oh_connection.py", line 99, in on_sse_event
[2019-04-19 09:27:44,191] [HABApp.openhab.connection]    ERROR |     event = get_event(event)
[2019-04-19 09:27:44,191] [HABApp.openhab.connection]    ERROR |   File "/usr/local/lib/python3.7/site-packages/HABApp/openhab/events/__init__.py", line 16, in get_event
[2019-04-19 09:27:44,191] [HABApp.openhab.connection]    ERROR |     raise ValueError(f'Unknown Event: {event_type:s}')
[2019-04-19 09:27:44,192] [HABApp.openhab.connection]    ERROR | ValueError: Unknown Event: GroupItemStateChangedEvent

Where does this error about the unknown event come from?

Docker container always terminates on Synology

Hi!
I am running HABapp on my docker host which is a Synology DS918+ NAS.
HABapp successfully created the config files in the config files.

However, even with two demo rules in the config folder the container terminates immediately.

The log files shows:

[2019-04-19 08:07:19,046] [                   HABApp]     INFO | HABApp Version 0.4.0
[2019-04-19 08:07:19,047] [   HABApp.mqtt.connection]     INFO | MQTT disabled
[2019-04-19 08:07:19,057] [                   HABApp]    ERROR | Traceback (most recent call last):
[2019-04-19 08:07:19,058] [                   HABApp]    ERROR |   File "/usr/local/lib/python3.7/site-packages/HABApp/__main__.py", line 71, in main
[2019-04-19 08:07:19,058] [                   HABApp]    ERROR |     app = HABApp.Runtime(find_config_folder())
[2019-04-19 08:07:19,058] [                   HABApp]    ERROR |   File "/usr/local/lib/python3.7/site-packages/HABApp/runtime/runtime.py", line 31, in __init__
[2019-04-19 08:07:19,058] [                   HABApp]    ERROR |     self.rule_manager = HABApp.rule_manager.RuleManager(self)
[2019-04-19 08:07:19,059] [                   HABApp]    ERROR |   File "/usr/local/lib/python3.7/site-packages/HABApp/rule_manager/rule_manager.py", line 46, in __init__
[2019-04-19 08:07:19,059] [                   HABApp]    ERROR |     watch_subfolders=True
[2019-04-19 08:07:19,059] [                   HABApp]    ERROR |   File "/usr/local/lib/python3.7/site-packages/HABApp/runtime/folder_watcher/folder_watcher.py", line 36, in watch_folder
[2019-04-19 08:07:19,059] [                   HABApp]    ERROR |     assert folder.is_dir()
[2019-04-19 08:07:19,060] [                   HABApp]    ERROR | AssertionError

Any idea what's wrong?
The config dir seems to be available readable and writable.

grafik

Error while loading logfiles with utf-8 filenames

Error message:

UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in position 28: ordinal not in range(128)
'ascii' codec can't encode character '\xfc' in position 28: ordinal not in range(128)
'ascii' codec can't encode character '\xfc' in position 28: ordinal not in range(128)

In the file there is a proper utf-8 chars which should work fine.
Maybe there's a conversion in the yaml loader?
-> Investigate further

Previous Issue

Use of Parameters in Examples seems wrong

The example for how to use parameters given here https://habapp.readthedocs.io/en/latest/parameters.html does not seem correct::

# construct parameter once, default_value can be anything
self.min_value = HABApp.Parameter( 'param_file_testrule', 'min_value', default_value=10)

I could not get this to work. The first argument has to be a HABApp.Parameters instance, and HABApp.Parameter doesn't seem right either.

I finally implemented parameters like this:

class FileParameters(HABApp.Rule):
    def __init__(self, filename):
        super().__init__()

        self.chromecast_params = self.get_rule_parameter(
                    filename,
                    'chromecast',
                    default_value={ 'http_server': '192.168.100.119',
                                    'chromecasts' : {
                                    'Google Home Upstairs': {'ip': '192.168.100.201', 'port': 8009},
                                    'Google Mini 1': {'ip': '192.168.100.80', 'port': 8009},
                                    }
                                  }
                    )
                    
        self.prowl_api = self.get_rule_parameter(
                    filename,
                    'prowl_api',
                    default_value='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
                    )

params = FileParameters('param_file_rules')

# Define chromecasts here
ccs=[]
for name, cc in params.chromecast_params.value['chromecasts'].items():
    #log.info('loaded chromecast_params: %s: host=%s port=%s http_server:%s' % (name, cc['ip'], cc['port'], params.chromecast_params.value['http_server']))
    ccs.append(GoogleHome(host=cc['ip'], port=cc['port'], ip=params.chromecast_params.value['http_server']))

I have to use .value all the time to access the stored parameters, is that what is intended? or am I using this wrong?

Thanks,

self.__future_events.append(future_event) raising errors

Recently I've been getting these error messages:

2019-12-17 17:19:43,017[             HABApp.Worker]ERROR|  __format_traceback: Error in TVControl.tv_lights_control: 'NoneType' object has no attribute 'append'
2019-12-17 17:19:43,018[             HABApp.Worker]ERROR|  __format_traceback: Traceback (most recent call last):
2019-12-17 17:19:43,021[             HABApp.Worker]ERROR|  __format_traceback:   File "/etc/openhab2/HABApp/lib/utils.py", line 391, in tv_lights_control
2019-12-17 17:19:43,022[             HABApp.Worker]ERROR|  __format_traceback:     self.set_tv_lights('ON')
2019-12-17 17:19:43,024[             HABApp.Worker]ERROR|  __format_traceback:   File "/etc/openhab2/HABApp/lib/utils.py", line 379, in set_tv_lights
2019-12-17 17:19:43,026[             HABApp.Worker]ERROR|  __format_traceback:     self.tv_lights_lockout['timer'].start()
2019-12-17 17:19:43,027[             HABApp.Worker]ERROR|  __format_traceback:   File "/etc/openhab2/HABApp/lib/utils.py", line 577, in start
2019-12-17 17:19:43,027[             HABApp.Worker]ERROR|  __format_traceback:     self._task = self.run_in(self.get_milliseconds, self.exec_func, *args, **kwargs)
2019-12-17 17:19:43,028[             HABApp.Worker]ERROR|  __format_traceback:   File "/home/nick/Scripts/HABApp/HABApp/rule/rule.py", line 372, in run_in
2019-12-17 17:19:43,028[             HABApp.Worker]ERROR|  __format_traceback:     self.__future_events.append(future_event)
2019-12-17 17:19:43,028[             HABApp.Worker]ERROR|  __format_traceback: AttributeError: 'NoneType' object has no attribute 'append'

not always on the same function, it varies. The error is always the same though.

I have tried the same action again that caused the error, but it subsequently works with no error.

This is after HABApp has been running for many hours with no errors, suddenly one of these error will occur, but when I repeat the action that caused the error, there is no error.

The above routine tv_lights_control is run when the TV is turned on or off. After I noticed the error, without changing anything I tried turning the TV on and off again, but no error occurred.

This is using the Dev branch of HABApp.

oh.post_update does not update item.value immediately

I just ran into a minor issue with post_update (probably send-command as well).

when I post_update a new value to an item, then immediately use the item.value the value is the old value, not the new value just posted.

I realize this is because the new value is sent to OH, and at some future time the value will be updated with the new value, but this is a bit of a `"gotcha" if you don't realize this.

for example, I post a timestamp update to a DateTime item, then immediately display the new value. I do this as OH is a bit pickey about the DateTime formats it accepts, and sometimes it doesn't "take". I noticed that the new value displayed was wrong (avtually the old timestamp) - This was when i realized the problem.

here is the problem code:

def update_timestamp(self, date_time_item):
        self.oh.post_update(date_time_item, self.dt)
        self.log.info('updated %s timestamp to : %s' % (date_time_item.name, date_time_item.value))

where self.dt is datetime.now()

The workaround is to do a, item.set_value() after the post_update but this isn't a great solution, as you don't then know what the actual value in OH is.

This is my slightly better workaround:

    def timestamp_update(self, event):
        self.log.info('updated %s timestamp to : %s' % (event.name, event.value))
        self.event.cancel()
        
    def update_timestamp(self, date_time_item):
        self.oh.post_update(date_time_item, self.dt)
        self.event = self.listen_event(date_time_item, self.timestamp_update, ItemStateEvent)

But the "gotcha" still exists - which is OK, as long as you are aware of it.

Group state aggregation not supported

Current implementation doesn't support group state aggregation. For example, this group item
Group:Switch:OR(ON, OFF) StudyRoom_Light "Study Room Light" <light> (gAutoOffLight)
And calling this method
self.get_item(“StudyRoom_Light”).is_on()
Would yield a python error stating that the object doesn't have a is_on() method.

QuantityType Items cause problems when trying to use them

Since OH 2.4 a new type QuantityType was introduced.
This makes calculations very difficult. items now are defined like this:

Number:Temperature  AeonMS61F "Temperature [%.1f °C]" <temperature> (gB, Sensors, Max_Temperature) {channel="zwave:device:controller:node29:sensor_temperature"}

If you want the units to be converted correctly (eg Celsius not Fahrenheit) - this is the only way to get the units reported correctly.

In HABapp these items values are returned as strings like this:

'29.5555555555555555555555555555556 °C'

Which makes performing comparisons with them difficult.
The workaround I have is this:

temp = get_int(self.item['AeonMS61F'].value.replace('°C', ''))

where get_int is a routine that attempts to make an number out of whatever you give it.
It would be very helpful if the item .value returned the integer or float value of a Number item (even if its also a QuantityType), perhaps the string could be returned as the __repr__ value or a new .formatted property.

It might be simpler to split the string at the first non-numeric character (that isn't.), but I just hacked the fix in quickly. There are obvious possible issues with - signs, , and so on, so it might need some thought.

OH does like to make things difficult, but I think it would be nice if we could work round their complications this way.

Comparing DateTime from openhab with datetime.datetime.now() throws TypeError

Comparing DateTime from openhab with datetime.datetime.now() results in the following error

TypeError: can't compare offset-naive and offset-aware datetimes

Solution:
Normalize values from openhab with

date = input_date.astimezone(tz=None)  # Changes datetime object it points to system timezone
date = date.replace(tzinfo=None)       # Removes timezone awareness

Processing events while file loading needs to be thread safe!

ERROR |   File "/opt/habapp/lib/python3.6/site-packages/HABApp/__main__.py", line 134, in main
ERROR |     loop.run_until_complete(app.get_async())
ERROR |   File "/usr/lib/python3.6/asyncio/base_events.py", line 473, in run_until_complete
ERROR |     return future.result()
ERROR |   File "/opt/habapp/lib/python3.6/site-packages/HABApp/rule_manager/rule_manager.py", line 64, in process_scheduled_events
ERROR |     for file in self.files.values():
ERROR | RuntimeError: dictionary changed size during iteration

ConfigStatusInfoEvent raises error

Just upgraded to OH 2.5.0-1, I'm seeing these errors:

2019-12-20 14:44:51,528[ HABApp.openhab.Connection]ERROR|        on_sse_event: Unknown Event: ConfigStatusInfoEvent
2019-12-20 14:44:51,529[ HABApp.openhab.Connection]ERROR|        on_sse_event: Traceback (most recent call last):
2019-12-20 14:44:51,529[ HABApp.openhab.Connection]ERROR|        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/events/__init__.py", line 24, in get_event
2019-12-20 14:44:51,530[ HABApp.openhab.Connection]ERROR|        on_sse_event:     return __event_lookup[event_type](_in_dict)
2019-12-20 14:44:51,530[ HABApp.openhab.Connection]ERROR|        on_sse_event: KeyError: 'ConfigStatusInfoEvent'
2019-12-20 14:44:51,530[ HABApp.openhab.Connection]ERROR|        on_sse_event:
2019-12-20 14:44:51,531[ HABApp.openhab.Connection]ERROR|        on_sse_event: During handling of the above exception, another exception occurred:
2019-12-20 14:44:51,531[ HABApp.openhab.Connection]ERROR|        on_sse_event:
2019-12-20 14:44:51,532[ HABApp.openhab.Connection]ERROR|        on_sse_event: Traceback (most recent call last):
2019-12-20 14:44:51,532[ HABApp.openhab.Connection]ERROR|        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/oh_connection.py", line 105, in on_sse_event
2019-12-20 14:44:51,532[ HABApp.openhab.Connection]ERROR|        on_sse_event:     event = get_event(event_dict)
2019-12-20 14:44:51,533[ HABApp.openhab.Connection]ERROR|        on_sse_event:   File "/home/nick/Scripts/HABApp/HABApp/openhab/events/__init__.py", line 26, in get_event
2019-12-20 14:44:51,533[ HABApp.openhab.Connection]ERROR|        on_sse_event:     raise ValueError(f'Unknown Event: {event_type:s}')
2019-12-20 14:44:51,534[ HABApp.openhab.Connection]ERROR|        on_sse_event: ValueError: Unknown Event: ConfigStatusInfoEvent

While I'm trying to fix the usual breaking changes in OH. I'm assuming these will stop once I get my things and items stable again, but it might be as well to handle them gracefully.

I just updated to V 11.0 by the way - no problems other than the above so far...

Getting messages 'X' took too long

I have just recently (on the dev branch) started getting these messages:

2019-12-16 14:30:02,868[             HABApp.Worker]WARNI|               __run: Execution of Alexa.realitem_update_received took too long: 1.26s
2019-12-16 14:30:13,507[             HABApp.Worker]WARNI|               __run: Execution of LuxtoText.item_state_update took too long: 1.09s
2019-12-16 14:40:49,397[             HABApp.Worker]WARNI|               __run: Execution of getTimestamp.12135.timestamp_update took too long: 1.16s
2019-12-16 14:42:53,089[             HABApp.Worker]WARNI|               __run: Execution of TVControl.update_received took too long: 1.02s

I did not get these previously (on the main branch), and none of these methods has anything in them that takes any time. None should take more than a few ms to execute.

eg: LuxtoText() is this:

    def item_state_update(self, event):
        self.log.debug('Item %s received update %s' % (event.name, event.value))
        if event.value is None:
            return
        for k,v in self.conversion_dict.items():
            if event.value <= v:
                text = k
                break
        else:
            text = 'Very Bright'
        
        self.log.info('%s lux(%s) set brightness level %s to: %s' % (event.name, event.value, self.text.name, text))
        self.oh.post_update(self.text, text)

where self.conversion_dict has 4 entries.
It seems like the post_update is taking too long. I have checked the VM processor load, and it's 7%, iowait 0.0%. No warnings in glances.

The messages seem to come in clusters, then nothing for a long time. I'll keep watching them, see if they correlate with any external events. The OH server HABApp is posting to is on the local VM using ip 127.0.0.1.

Suggested Improvement for SwitchItem

I have a suggestion for SwitchItem.

Right now, a SwitchItem only accepts boolean values, ie 'ON' or 'OFF'. This makes things difficult what you are setting switches to be controlled by DimmerItems which use both OnOff and percent types. I can control a DimmerItem with a SwitchItem, as the DimmerItem accepts 'ON' and 'OFF' inputs, but not vice versa.

My workaround is this:

if isinstance(master_item, SwitchItem):
    if event.value > 0:
        event.value = 'ON'
    else:
        event.value = 'OFF'

Which is horrible.

I would suggest adding PercentCommand to SwitchItem such that any value > 0 is ON and 0 is OFF.
This way, a SwichItem can be controller by a DimmerItem`.

Here is my hack for SwitchItem:

if isinstance(new_value, OnOffValue):
    new_value = new_value.value
elif isinstance(new_value, PercentValue):
    new_value = OnOffValue.ON if new_value.value > 0 else OnOffValue.OFF

Should really add percent as a method to OnOffCommand as well, but I haven't figured out how all this goes together yet.

so then you can do this:

flouro_item = self.get_item('basementFluorescents')
flouro_item.set_value(event.value)
self.log.info('setting basementFluorescents to %s' % flouro_item)
self.oh.post_update('basementFluorescents', flouro_item)

and it doesn't matter if event.value is 'ON', 'OFF', or a percent number.

What do you think? is it worth doing? I can make my own routine to figure this out, but this would be more elegant.

Race condition on Restored items

This is a bit of an odd one (and i am on 0.8.0 now).

I had to reboot my OH VM. I started HABApp, but OH takes a while to get going.

I found that Items that are restored by persistence at startup sometimes give states of None, even after they have been restored. Not all of them do, just some.

The only way out of this was to restart HABApp, when the state of the items was then picked up.

This is a big problem when restarting, as it's hard to tell when an Item state has been restored by persistence, and HABApp does not pick up the new restored state, it just keeps reporting None as the state.

The item does exist as far as HABApp is concerned (I checked), just HABApp gets the wrong state when using get_item_state() or any of the other item methods.

Does get_item_state() not pull the value directly from OH? is it using a local cached version that does not get updated when items are restored by persistance? is there a way of forcing an update?

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.