Home Graph Solid Base For 1000+ Items

After playing around with HA for a few months I come to realize that a graph model of the home would have saved me a lot of problems. The names of the various items would have been fully consistent. And managing scenes from room to room or the house overall would be much easier.

At this point HA items (switches, sensors, etc.) are loosely configured. Which makes sense when a project naturally grows. However from a broader perspective it isn’t the most solid base for the future IMO. As configurations grow it is easy to loose overview over which items belong where and what there functions are.

With the 20 switches and 30 sensors I have, and enough programming experience I manage to still keep things in control at the moment. But when we look to the future it wouldn’t be crazy to assume we might end up with well over 1000+ items in our configurations.

Items should therefor have a footing in a bigger structure. That way you would be able to scope commands and reduce global listeners. Which would enable partial configuration reloads. Moreover configuration and state updates could be directly written on a graph database.

I just came across https://www.home-assistant.io/docs/configuration/platform_options/ which describes entity_namespace. Which could prevent some problems with naming inconsistencies. But surely that isn’t the biggest problem IMO

Hmm I have more than 700 items in my system and I don’t have a problem managing these. Maybe I misunderstand you, but you can put items in group or you can put things inside packages for easier management.

Also HA is currently in transition from text based to GUI configuration, in the future I assume that most integrations can be setup through a GUI, this way you see all devices belonging to an integration in the same place.

1 Like

Yes, I use packages too to separate the configuration. The automation for those items are stored in separate files. So, the naming problem is solvable; provided that you have enough knowledge of the config options.

Though addressing the various items in an automation can become a tedious process. For instance to detect presence I have the following automation

- alias: Set Presence on PIR 
  trigger: 
    - platform: state
      entity_id:
        - binary_sensor.motion_sensor_158d0002f08322
        - binary_sensor.motion_sensor_158d0002f0839e
        - binary_sensor.motion_sensor_158d0002f9c772
        - binary_sensor.motion_sensor_158d0002f9c944
        - binary_sensor.motion_sensor_158d0003cd87cb
        - binary_sensor.motion_sensor_158d0003cd887f
  action:
    - service: input_text.set_value
      data_template:
        entity_id: "input_text.presence_{{trigger.to_state.state}}"
        value: "{{ trigger.to_state.attributes.friendly_name}}"
    - service: input_text.set_value
      data_template:
        entity_id: input_text.presence
        value: >
          {% set ns = namespace(written=0) %}
          {% set triggername = trigger.to_state.attributes.friendly_name %}
          {% for item in ['158d0002f08322','158d0003cd887f','158d0002f0839e', '158d0002f9c772','158d0002f9c944', '158d0003cd87cb'] %}
                {% if ns.written == 0 and states('binary_sensor.motion_sensor_'+item) == 'on' %}
                true
                {% set ns.written = 1 %}
                {% endif %}
          {% endfor %}
          {% if ns.written == 0 and states('input_text.presence_on') == triggername and trigger.to_state.state == 'off' %}
                {% if triggername == 'Motion Corridor' or triggername == 'Motion Hallway' %}
                false 
                {% else %}
                true
                {% endif %}
                {% set ns.written = 1 %}
          {% elif ns.written == 0 and trigger.to_state == 'off' %}
                {{states('input_text.presence')}} 
                {% set ns.written = 1 %}
          {% endif %}
          {% if ns.written == 0 %}
          true
          {% endif %}

which is messy, but it works.

Now if I want to know in which room a user is as he moves through the house, I have to write something similar again… Whereas if items where embedded in a bigger graph-like structure this would become a much simpler task. Maybe I am missing some knowledge about the config lang.

– edit –
Next to that it now only works for the sensors I give it. But switches and other devices can also give an indication of presence. e.g. I manually switch a button in a room where there is no PIR sensor available.

I think the best solution to your problem is to wrap all the presence sensors in a input_boolean.

Is there a reason this doesn’t work?

1 Like

Thanks for your suggestion. I could have used a boolean in the code above. But I guess that is not what you meant.

I’m using xiaomi mi motion sensors. They set the state to ‘on’ if presence is detected and it keeps this state till no motion was detected plus (about) 2 min. The code above works fine for that. Next to the pir sensors I have wifi switches in all rooms (not all rooms have pir sensors). When I manually switch those it could be counted as presence in that particular room. But I have also automations running which can switch the lights. At this point there is no way of telling what triggered the light. In Awesome Switch triggered_by Attribute For Happy Automations! suggested an extra attribute (or a source as someone else proposed). Of course I can work around the issues to get it to work. But I realized this can become a big problem in the future, hence this topic.

Hmm you could also create an input_boolean for each room and then let the motion sensors and your manual switches turn this input_boolean on/off. How do you want to determine which user activated the motion sensor or the manual switch?

I have a raspberry pi zero in most of my rooms and a NUT mini BLE device attached to each of the keys of the persons in the household. The NUT mini sends a signal every 3 seconds I think and the raspberry pis receive the signal and based on the signal strength they decide in which room the NUT mini is thanks to this software https://github.com/mKeRix/room-assistant

I’m planning on cutting a hole in our slippers and put the tracker in there, a bit more convenient than carrying the key all the time. However this is not really on top of my to-do list as I have yet to find a use case for room-based presence detection. General presence detection works without any issues for me since about 1 year, no false triggers, presence detected as soon as I’m close to the main door.

Could you maybe give me an idea on an automation to do with room-based presence detection?

1 Like

That wasn’t in the plans yet, but would be kinda neat. Everyone could have their own presets per room.

For example in my living I have 4 infrared heating zones. I can switch those based on presence. It’s not useful to heat the kitchen area when there is only presence in the lounge area detected. (If you know who is present you could also set the desired temperature, maybe even dependent on the activity (cleaning/relaxing/working/etc.))