Announcement

Collapse
No announcement yet.

Decoupling logical states from phisical devices (and events from triggers)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Decoupling logical states from phisical devices (and events from triggers)

    Hello everyone. I am new to HomeSeer and currently in the process of migrating from OpenHab after few years of usage (to which I migrated from Domoticz ).

    I would like your oppinion on separating states from phisical devices, and action trigers from actions. A bit long explanation, but this is kinda important before I start, thanks for patience.

    Since I am developer I sort of think about abstractions (and obviously sometimes overengineering things), so what I found that works for me logically is to separate states from devices, thus having less places to change things when adding/changing devices and actions. But does this makes sense in homeseer?
    In my mind there are some states, actions, scenes and triggers

    For example, the virtual device/state "someone in the house" would derive its state from virtual devices like "me in the house", "wife in the house" and "guests in the house". Wheres "me in the house" would come from my phones connection, and "wife in the house" would be her phone + motorcycle keys bluetooth beacon (as she forgets the phone sometimes). Guests are determined by their wifi connection to guest network on Unifi.

    Other examples would be something like:
    • Presence:
      • Someone home / no one home / all home
        • Me home
        • Wife home
        • wasp result
        • Guests present (wifi?)
      • Someone on way from work (me, wife)
      • Someone sleeping
        • left bed side occupied
      • Someone sitting at the table
        • chair 1 occupied
        • chair 2 occupied
        • ...
    • Comfort
      • Sun luminosity in the room
        • Now
        • Last two days
      • Temperature (Yesturday / today / tomorrow)
        • livingroom
        • outside
      • Time periods
        • Deep sleeping time
        • Work day waking period
        • Family dinner time period
        • Kids preparing to sleep

    Here I can have one place that configures a state, since a lot of actions are using states I only have one place to change (f.eks. as kid is growing, "Kids preparing to sleep" changes a bit, or if I change how presense is determined I do it one single place).

    I would then have actionable items
    • Actionables:
      • All blinds up / down
        • Living room blinds up / down
        • Office blinds up / down
      • Lights color (per room)
        • cool
        • normal
        • warm
        • movies
        • disco
      • Lights luminocity
        • min
        • low
        • normal
        • dynamic
      • Multimedia
        • Watchi youtube
        • Watch Plex movies
        • Listen to Plex music
    Again logic is that I have some hue lights, and I switch to Ikea lights... Or watchining plex movies might trigger trought Logitech harmony integration, or perpahs I write some script, or I change device and now it is apple tv... Scenes do not change as they do not care what devices are performing the action

    Then based on that I can then build some activities/scenes, f.eks.
    Scenes:
    • having breakfast
    • having lunch
    • having Dinner
    • Preparing kids to sleep
    • watching movies
    • watching home videos
    • listening to music
    • someone is vacuuming
    • wife is studying

    Last thig are various triggers that would either control activities, or some simple automations (typical one motion - one light)
    For example:
    - time is "family dinner time period", and at least 2 chairs are occupied -> activate "having Dinner" scene (get more lights above dinner table, dim other lights in the room, play some music, maybe lower phones volume etc.)
    - plex is playing something from home videos folder, and there are guests present -> activate "wathing home videos" scene (adjust lights, lower blinds, on pause adjust lights back).

    The reason from separating activities and triggers is that some scenes can be triggered both automatically (time, activity) and manually (asking google/phone/tablet/phisical switch). And for this different proxy items and flag items are needed, to determine if lights are overriden manually and when should they go back to auto state etc. Also activities usually have "dead man's switch" directly in them, thus they will not activate regardles of which scene was activated.

    I've read a lot of forum posts on organizing events and phisical devices, but obviously not all as it is quite huge (even though I am of those who believe that size is not important), so I am thanfull if you point me into related topics as well.

    Does all this complication makes sense for experienced homeseer users, or am I overengineering very simple things?
    Any thoughts about how to do this in homeseer before I start doing it "the wrong way"?
    Last edited by dakipro; September 23, 2019, 03:43 AM. Reason: tags

    #2
    What you are describing makes good sense. I try to do something similar (but with less structural intention). The way I do it is with devices (usually referred to as 'virtual' devices on the Board) that represent the states. So, I have a device for occupancy of the house, others for occupancy of each room, state of the alarm system, presence or absence of each vehicle, presence or absence of guests, garbage collection day, holidays, season of the year, etc. I then use the state (value) of those devices as conditions and triggers for events.

    Generating scenes is also a common approach. The mechanics for constructing a scene will be dependent on the hardware you are using, so it's difficult to describe a general solution that is more specific than what you have described.

    If you have not done so yet, I strongly recommend that you spend some time reviewing the threads in the Event Clinic. There are many useful tips and hints there, as well as some illustrations of ways to do the kinds of things you describe. Of course, you will find that you have circumstances that are unique, or think of ways to do things that work better for your situation, so it will be a starting point only.
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

    Comment


      #3
      Thanks, I will read more about best practices and examples while in the migration process, there are a lot of details.
      For what I described above, would you recommend using on/off flags, or using 0,1,2,3....100 values? I guess that for states that can never be overlapping, perhaps using multiple values on single device makes more sense. F.eks. Multimedia status cannot overlap, either it is watching home videos, or youtube or listening to music, so for me that makes sense to be single virtual device with multiple values, rather then youtube on/off, music on/off, home videos on/off, or is there some advantage of one vs the other?

      Comment


        #4
        Everyone will have their own take on the best way to represent states. I use both on/off and multiple choice depending on the circumstance. I also use bit values in a few cases, so the total device value can be analyzed for the components if they are not mutually exclusive. HS offers considerable flexibility to adapt it to what you want to achieve and the way that makes the most sense to you.
        Mike____________________________________________________________ __________________
        HS3 Pro Edition 3.0.0.548, NUC i3

        HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

        Comment


          #5
          I am doing something very similar to what you are describing. My own approach is motivated mostly by three factors:

          Decoupling switches from the lights they control (I use HomeSeer switches on the wall but control my downlights with an Arduino board.)
          Needing to separate "automated" on off triggers, like motion sensing, from "manual" on/off triggers like light switches and Alexa commands.
          The ability to replace physical sensors/switches/actuators in the future with minimal need for re-programming events.

          Some examples:


          Physical Switch (HS-WD200) -> HS3 Event -> Virtual Device "Manual Lighting" -> HS3 Event -> Physical Light (Arduino Pin 1)

          Physical Motion Sensor (HS-MS100) -> HS3 Event -> Virtual Device "Motion Sensing" -> HS3 Event -> Physical Light (Arduino Pin 1) IF "Manual Lighting" = Off

          Virtual Device "Motion Sensing" -> HS3 Event -> Trigger Camera1 Recording (IF Virtual Device "Home Occupation" = Not Occupied)


          In the above scenario:

          If the physical motion sensor failed or was replaced with something better in the future, I would have to edit 2 different events (in reality more), the lighting and the camera trigger. By tying the physical motion state to a virtual device and triggering events from the virtual deivce, I only need to edit the event that ties the motion sensor to it's virtual representation, everything else will continue to work past that point.

          I use events to link devices rather than the "linked devices" setting, as a given sensors values might vary from whatever replaces it. Eg one motion sensor uses 0 = No Motion, 1 = Motion. The next uses 0 = No Motion, 100 = Motion. And the third uses 0 = No Motion, 8 = Motion. The linked devices setting replicates the numerical value, rather than the state it's meant to represent.

          In the case of the motion lighting, without the "Manual Lighting" logic check, then every time the motion timer expired the lights would turn off, even if the user had pressed the switch with the intention of keeping the light on.


          I think you're on a good path with your reasoning, and I wish I'd come into HomeSeer with a similar understanding from the beginning. It would have saved me a lot of double handling on setting things up.

          Comment


            #6
            Thanks Fellhahn I am also using some arduino stuff, mostly based on MySensors library. What protocol are you using?
            Also would you mind sharing som screens of how your devices/events are organized, perhaps some important steps that are tricky for new users?

            Since you mentioned proxy/flag switches that control rules, I am curious about your thoughts on this use case:
            - light would adjust based on luminosity sensors and change its brightness over longer time period. Then user comes and manually increases the light with a switch/google/mobile, now the system would switch control to manual and stop adjusting the lights.

            I've seen examples of how this is done here on the forum, but I am yet to check details. Anyway, the way I did this in node-red is to have three items, ActualLightsValue(1-100), AutomationState(Auto, Manual) and LastAutomationValue(1-100).
            All light events/rules would populate LastAutomationValue if AutomationState is Auto. ActualLightsValue would be monitored for changes and if its new value is different from LastAutomationValue (+-few percent for z-wave) then this means that someone else interacted with the lights directly, so AutomationState would switch to Manual and light rules would stop.
            This is similar to examples I've seen online, but different in a sense that system would track changes on the light itself, rather then on the dedicated proxy/flag item. Not sure if I am making sense here, maybe this is a question for another topic when I get a bit more familiar with homeseer.
            This applies to other areas such as heating, even music etc. I was about to make node-red plugin for this, but never got the time to do it.

            Comment


              #7
              Originally posted by dakipro View Post
              . . .system would track changes on the light itself, rather then on the dedicated proxy/flag item.
              Tracking changes made locally will depend on the capabilities of the hardware. Ideally, the device will inform HS of any changes in state, but many devices have no provision for that. Some devices need to be polled for their state, but polling scores or hundreds of devices frequently can overload the communication channel. To make the strategy work, you will need to pay attention to your hardware choices.


              Mike____________________________________________________________ __________________
              HS3 Pro Edition 3.0.0.548, NUC i3

              HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

              Comment


                #8
                That is a good point. I have mostly z-wave+ and zigbee from ikea and xiaomi, I was pretty sure they all report status on their own but I will certainly double check.

                Comment


                  #9
                  I use the HS3 Arduino plugin written by enigmatheatre

                  In terms of grouping events, at the moment I have an event group for all the "motion sensing", these are the events that tie physical sensors to their virtual clones:

                  Click image for larger version

Name:	Capture1.PNG
Views:	247
Size:	254.6 KB
ID:	1328853


                  I have an event group for "Motion lighting", this is where the logic check happens about whether a a room has been switched on manually or not. If not, the physical light is turned on:

                  Click image for larger version

Name:	Capture2.PNG
Views:	186
Size:	279.8 KB
ID:	1328855


                  A similar event group for "manual lighting", very similar to motion lighting but without the logic check on another virtual device:


                  Click image for larger version

Name:	Capture3.PNG
Views:	194
Size:	215.4 KB
ID:	1328854

                  The second action in that last image simply sets a status LED on another switch in the house, reminding me that the light is on (manually) in another room.

                  Then finally I have an event group for each room, that ties virtual motion sensing to the virtual motion light devices, and switch interactions with the manual lighting virtual devices.


                  Click image for larger version

Name:	Capture4.PNG
Views:	192
Size:	397.3 KB
ID:	1328856

                  The "virtual manual lighting" devices are the ones that I enable for voice and present to Alexa for voice control.

                  Click image for larger version

Name:	Capture5.PNG
Views:	183
Size:	334.4 KB
ID:	1328857


                  I don't do software development or programming for a living, so I'm by no means an authority on designing efficient events. This is just what I'm using as it makes sense to me and helps me keep track of events and how they flow.

                  Comment


                    #10
                    Thanks Fellhahn, it is much appreciated!
                    Short question, on the "Motion Lighting", the second image, first event for "Entry off" has condition If it had value to OFF, and it becomes OFF. Does that mean you are looking for "value change" (vs state change)? Meaning, it can happen that Virtual Motion-Lighting Dining can get out of sync or it can somehow receive Off two times in a row?

                    Btw you do not need to be developer for living to write a good "code" or to program a machine And the other way around, being a professional does not necessarily mean you are good at it (same goes for photography, mechanics, plumbing etc...)

                    Comment

                    Working...
                    X