Group visibility idea's /help for violated zone front end panel

I am about to start on a new project and was looking for suggestions before I start. I have HA connected to my alarm with 30+ door / motion / window sensors. I want to have only the sensors that are violated / open to appear on the front end and the rest hidden. I was thinking of putting each sensor in its own group and then automate each group visibility if state is on. While this is simple to do, this will require 30+ automations and groups. Is it worth learning app daemon or another way to accomplish this if it can?

I setup one sensor to hide when off and show when on. Is there a way to do this for every sensor without just copying below 30 times?

group:
  group_binary_sensorfamily_room_motion:
      - binary_sensor.family_room_motion


automation hide:
  trigger:
    platform: state
    entity_id: binary_sensor.Family_Room_Motion
    to: 'off'
  action:
    service: group.set_visibility
    entity_id: group.group_binary_sensorfamily_room_motion
    data:
      visible: False
automation show:
  trigger:
    platform: state
    entity_id: binary_sensor.Family_Room_Motion
    to: 'on'
  action:
    service: group.set_visibility
    entity_id: group.group_binary_sensorfamily_room_motion
    data:
      visible: True

I haven’t tested this, but an app to do this using appDaemon would be something like



import appdaemon.appapi as appapi

# App to hide groups that are off
# Args
# groups: list of group names to hide

class HideGroups(appapi.AppDaemon):

    def initialize(self):
        for group in self.split_device_list(self.args["groups"]):
            self.listen_state(self.status_changed, "group." + group)

    def status_changed(self, entity, attribute, old, new, kwargs):
        if new == "on":
            self.call_service("group/set_visibility", visible=true)
        elif new == "off":
            self.call_service("group/set_visibility", visible=false)

with this in appdaemon.cfg

[group_hide]
module=hide_groups
class=HideGroups
groups=group_binary_sensorfamily_room_motion,group_binary_sensorKitchenRoomMotion

You can add as many group names as you like to the groups line.

2 Likes

Thanks for the help. I installed the app and removed my old automations but I can’t get it to work. This is my first app daemon so it might be something simple

I added this to appdaemon.cfg

[group_hide]
module=hide_groups
class=HideGroups
groups=group_binary_sensorfamily_room_motion

and get this

2017-03-23 13:14:57.977500 INFO AppDaemon Version 1.5.2 starting
2017-03-23 13:15:03.560698 WARNING ‘elevation’ directive is deprecated, please remove
2017-03-23 13:15:03.561011 WARNING ‘latitude’ directive is deprecated, please remove
2017-03-23 13:15:03.561512 WARNING ‘longitude’ directive is deprecated, please remove
2017-03-23 13:15:03.561661 WARNING ‘time_zone’ directive is deprecated, please remove
2017-03-23 13:15:08.690486 INFO Got initial state
2017-03-23 13:15:08.691562 INFO Loading Module: /Users/xxxxx/.homeassistant/apps/group_hide.py
2017-03-23 13:15:08.692442 INFO Loading Module: /Users/xxxxx/.homeassistant/apps/hello.py
2017-03-23 13:15:08.692999 INFO Loading Object hello_world using class HelloWorld from module hello
2017-03-23 13:15:08.740475 INFO hello_world: Hello from AppDaemon
2017-03-23 13:15:08.741356 INFO hello_world: You are now ready to run Apps!
2017-03-23 13:15:08.741479 INFO App initialization complete
2017-03-23 13:15:08.774475 INFO Connected to Home Assistant 0.40.1

on the front end default view where I added the group, it starts off and stays visible when status is on and off.

The log I got when I triggered motion sensor is

2017-03-23 13:37:23.315888 DEBUG Entity ID:group.group_binary_sensorfamily_room_motion:
2017-03-23 13:37:23.317685 DEBUG Event type:state_changed:
2017-03-23 13:37:23.317782 DEBUG {‘old_state’: {‘state’: ‘off’, ‘last_changed’: ‘2017-03-23T20:37:18.062918+00:00’, ‘entity_id’: ‘group.house’, ‘last_updated’: ‘2017-03-23T20:37:18.062918+00:00’, ‘attributes’: {‘view’: True, ‘entity_id’: [‘media_player.theater_room’, ‘media_player.living_room’, ‘binary_sensor.smoke_detectors’, ‘binary_sensor.sprinkler_flow_switch’, ‘binary_sensor.sump_pump’, ‘binary_sensor.tamper_box’, ‘sensor.home_alarm_keypad’, ‘sensor.yr_symbol’, ‘sun.sun’, ‘group.outside’, ‘group.family_room’, ‘group.upstairs’, ‘group.basement’, ‘group.front_house’], ‘hidden’: True, ‘friendly_name’: ‘House’, ‘order’: 8, ‘assumed_state’: True}}, ‘entity_id’: ‘group.house’, ‘new_state’: {‘state’: ‘on’, ‘last_changed’: ‘2017-03-23T20:37:23.306224+00:00’, ‘entity_id’: ‘group.house’, ‘last_updated’: ‘2017-03-23T20:37:23.306224+00:00’, ‘attributes’: {‘view’: True, ‘entity_id’: [‘media_player.theater_room’, ‘media_player.living_room’, ‘binary_sensor.smoke_detectors’, ‘binary_sensor.sprinkler_flow_switch’, ‘binary_sensor.sump_pump’, ‘binary_sensor.tamper_box’, ‘sensor.home_alarm_keypad’, ‘sensor.yr_symbol’, ‘sun.sun’, ‘group.outside’, ‘group.family_room’, ‘group.upstairs’, ‘group.basement’, ‘group.front_house’], ‘hidden’: True, ‘friendly_name’: ‘House’, ‘order’: 8, ‘assumed_state’: True}}}

I solved most of my problems. I had to renamed the app to hide_groups.py which solved my problem with installation. I had to change visible=true to visible=True and false to False in the app which got it working.

However, I am experience a strange effect where it works as it should except when it hides a group, it also hides my two unrelated calendar groups. This is a different outcome than when done without app daemon. I will experiment further to see if I determine why. Also, I am looking for way to get the initial visibility to False as it appear to start True.

I installed the 36 sensors into groups and setup the app and I think it was overloaded. I got these errors while the front end had groups popping in and out while all sensor were off. I moved the thread = all they way up to 700 and it didn’t help.

2017-03-23 16:44:33.002796 INFO App initialization complete
2017-03-23 16:44:33.058045 INFO Connected to Home Assistant 0.40.1
Queue size is 150, suspect thread starvation
Queue size is 260, suspect thread starvation
Queue size is 350, suspect thread starvation
Queue size is 400, suspect thread starvation
Queue size is 550, suspect thread starvation
Queue size is 550, suspect thread starvation
Queue size is 550, suspect thread starvation
Queue size is 580, suspect thread starvation
Queue size is 670, suspect thread starvation
Queue size is 690, suspect thread starvation
Queue size is 720, suspect thread starvation
Queue size is 820, suspect thread starvation
Queue size is 970, suspect thread starvation
Queue size is 1050, suspect thread starvation
Queue size is 1120, suspect thread starvation
2017-03-23 16:47:02.006950 INFO appdaemon/conf/appdaemon.cfg modified
Queue size is 1170, suspect thread starvation
Queue size is 1300, suspect thread starvation
Queue size is 1310, suspect thread starvation
Queue size is 1480, suspect thread starvation
Queue size is 1600, suspect thread starvation
Queue size is 1630, suspect thread starvation
2017-03-23 16:47:26.582154 INFO AppDaemon is shutting down

This is not something I have seen before. Maybe @aimc can help?

Do you still have the problem of multiple groups becoming invisible?

Nice job debugging my code, btw.

What this means is that something in the app is blocking and not returning the thread to the pool, or whatever the threads are doing is taking too long. Eventually you run out of threads, and AppDaemon starts queueing the requests up waiting for threads to become free. It is very unusual for this to happen during normal operation so I suspect something is wrong with the code.

My rookie guess is that the app is looking at the group state instead of the actual sensor state which might add a layer of delay and processing before execution of the app. By doing it this way, it reduces the amount of inputs by 1/2 as the group state is watched and the same group becomes invisible/visible. I can confirm that the automation approach works fine with 36 sensors groups and 72 hide / show automation. I put all the group sensors into another group called alerts. I found that this kept my other groups from moving around the page and kept the other two calendar group visible while using automations (not the app). The calendar groups still disappeared using the app with along with going haywire with everything popping in and out. I get this from the app when using group sensors in the alert group. I triggered the basement door (not the front door as in the first error below) and get the following plus many pages of similar errors.

2017-03-24 07:28:05.609913 INFO App initialization complete
2017-03-24 07:28:05.645685 INFO Connected to Home Assistant 0.40.1
2017-03-24 07:28:25.439351 WARNING ------------------------------------------------------------
2017-03-24 07:28:25.439614 WARNING Unexpected error in worker for App group_hide:
2017-03-24 07:28:25.439805 WARNING Worker Ags: {‘type’: ‘attr’, ‘function’: <bound method HideGroups.status_changed of <hide_groups.HideGroups object at 0x1049c18d0>>, ‘new_state’: ‘off’, ‘name’: ‘group_hide’, ‘kwargs’: {}, ‘id’: UUID(‘e400b6d6-cbbe-4aab-b2d2-30167d095b69’), ‘attribute’: ‘state’, ‘old_state’: ‘off’, ‘entity’: ‘group.front_door_alert’}
2017-03-24 07:28:25.439956 WARNING ------------------------------------------------------------
2017-03-24 07:28:25.443563 WARNING Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py”, line 600, in urlopen
chunked=chunked)
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py”, line 345, in _make_request
self._validate_conn(conn)
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py”, line 844, in validate_conn
conn.connect()
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/packages/urllib3/connection.py”, line 326, in connect
ssl_context=context)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/packages/urllib3/util/ssl
.py", line 324, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py”, line 377, in wrap_socket
_context=self)
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py”, line 730, in init
self.getpeername()
OSError: [Errno 22] Invalid argument

During handling of the above exception, another exception occurred:

I had to renew my ssl cert and that cleared the apps problem above. The app isn’t getting triggered at all now, it doesn’t give any indication a group sensor is tripped. I did change the group sensor control to hidden but docs says that only affect front end. I’ll change back and play with it more today and report back.

1 Like

I think the issue is that if you put a sensor in a group and that sensor is on, the group state in unknown. This is a my alert group of groups. Each group has one sensor or switch which is automated to disappear when the switch / sensor is off. There are 36 groups in the alert group which reduced my previous front end by two pages. A possible feature request would be to add visibility to entities based on a state parameter (or hard coded to their own state so the parameter would be only on/off). You can see the unknown state of the groups with sensors in them below.