home-assistant / android

:iphone: Home Assistant Companion for Android
https://companion.home-assistant.io/
Apache License 2.0
2.28k stars 629 forks source link

Linking WiFi names the phone is connected to with zones for person tracking #620

Open drthanwho opened 4 years ago

drthanwho commented 4 years ago

Is your feature request related to a problem? Please describe. I have often noticed that my location isn't updated for example when I leave home and come to work until I open the app or it does update but it is 4+ hours later, even though I have disabled battery optimisations. However, I often see it has updated which wifi it has connected to.

Describe the solution you'd like So I was thinking if it would make sense to be able to link wifi names (or bssid in case of same names) to locations for updating a person's zone. e.g. When connected to home's wifi it should know I'm home and if it's connected to work's wifi to change to work etc. This would also be a workaround for people who don't have or don't want to have GPS on (whether that is battery draining or personal preference).

Describe alternatives you've considered, if any A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

energywave commented 4 years ago

This is a wonderful idea! I strongly support it! I also have the exact same problem with the app on my phone (Samsung S8) and my wife (Xiaomi Mi A2 lite). the zone is updated with great delay (sometimes hours...) I was expecting at least geofencing to be more reactive but it isn't. Both phones have deactivated battery optimization and have the constant update of GPS from the app. I've managed to get a workaround using wifi as you suggested in Home Assistant, with an automation that set the status of the person to a specified zone when a certain SSID was connected to his phone and set the status not_home when that specific SSID disconnected (I did uses the set_state phyton script, if you're interested). With that workaround I could get precise notification on my home Alexa when I'm leaving the office (SSID disconnect after a certain time) and so on. But there is a problem, home assistant companion app update then again the state with the old zone based on an outdated GPS position, so there are "zone bouncing" you can see here (look just after 14:00, my zone was set to "Poliware" that's my office, based on the SSID automation I mentioned before, but just after that the app returned to home zone based on an old GPS position, detecting then the correct zone "Poliware" after 10 min. image

The solution to set specific SSID to zones would be WONDERFUL to have a WONDERFUL zone tracking in the app, that would be perfect, even in case of GPS poor reception, or GPS deactivation, like said from the author of the issue. An improvement idea could be to force a GPS reading when SSID changes or some specific configured SSID connect/disconnect happens, if SSID/zone association if too difficult to achieve.

werra11 commented 4 years ago

I would like to add something related to this suggestion. It would also be a great addition to change the connect URL based on the connected SSID. So not only a few specific home SSID's (wich already was great addition!) So as an example, connect to 192.1.1.1 when connected to the SSID named Home1 and connect to 192.2.1.1 when connected to the SSID named Home2. This would be great for people with multiple homes. The external SSID could be defined by location / just a single one.

energywave commented 3 years ago

@werra11: this seems more related to multi homes. I have one home only so I'm not interested at the moment but I could have that at office one day. I would not like to control only the "home" where I'm in, I want to control it from remote! So I think that would be better to handle that specific aspect with something like "multi homes" configurable, but that's another matter. I hope that SSID for zones would be taken in consideration as that will be a GREAT addition and will work very fast for zones detection. I'm simulating it but doing it native from the app as told above can totally remove bounce and give a very useful information in a fast way.

energywave commented 3 years ago

6 months passed, no mentions from authors. Are you considering this? Don't you think this could be valuable as we do? Do you have thoughts? Perplexity on something? Can you please give us a feedback, even a small one please? Thank you for your wonderful work that we use with love, however πŸ‘

mhetzi commented 3 years ago

Hi, it is sad, that this feature is not implemented. This app is great, but when i move between rooms sometimes it marks me as away. Why not stop the location tracking as long as the phone is connected to the home wifi. image ^ Didnt leave my house all day

dshokouhi commented 3 years ago

it is sad, that this feature is not implemented.

I am sorry you feel that way, we are open source and a group of volunteers so anyone can come and build this feature

Why not stop the location tracking as long as the phone is connected to the home wifi.

did you make sure to check: https://companion.home-assistant.io/docs/troubleshooting/faqs/#location-is-not-updating-in-android-app and you can also check the device logs (as detailed in this troubleshooting section) to look at the location process and make changes to location settings.

6 months passed, no mentions from authors. Are you considering this? Don't you think this could be valuable as we do? Do you have thoughts? Perplexity on something? Can you please give us a feedback, even a small one please? Thank you for your wonderful work that we use with love, however

We are all a group of volunteers and open source anyone is able to submit a PR and get it in the app.

If you guys really want this feature just use the wifi connection sensor in the meantime, it will do everything you need minus the pretty map, but for the purpose of an automation it will suffice.

energywave commented 3 years ago

I am sorry you feel that way, we are open source and a group of volunteers so anyone can come and build this feature

I know you're volunteers so I'm absolutely not pretending anything. I greatly appreciate your work as I love the app (as I wrote before :) ) I'm only hoping you'll find this suggestion a valuable one for future updates of the app. I'm a developer myself but unluckily I never developed for Android so I cannot make a PR :( Otherwise I would have done it ;)

If you guys really want this feature just use the wifi connection sensor in the meantime, it will do everything you need minus the pretty map, but for the purpose of an automation it will suffice.

As I wrote I'm doing it with automations when an SSID change is detected I set the state of the device_tracker to what it should be and it's working great and fast (only drawback is bounce of the status, as described in details). As I know how well this is working I would love to see such a great addition to the app so that everyone can benefit from this feature without making complex automations to achieve this. Hoping you get the point and understand how great would be such a feature and, I believe, not too complex to code it. Thank you for all your work that we all love πŸ‘

dshokouhi commented 3 years ago

(only drawback is bounce of the status, as described in details)

This has been fixed as of version 3.0.2 there is no more bounce back.

Has everyone in this thread re-evaluated the location tracking since version 3.0.2? We had a lot of very important location fixes that corrected many issues with the device tracker. I see a lot of the comments here are from when we had bouncing issues with the tracker so I wonder if the original intention behind this request is still valid. All of the issues mentioned in the original post have since been resolved. We had even more location fixes in the latest beta as well if 3.0.2 is not good enough for you.

For users who are experiencing bounce back we will need to look at the crash logs from the latest beta to ensure you have all the latest fixes so we can see why its bouncing. The bouncing was caused by Google sending us location updates that were very old and we now evaluate them properly. The debug logs that we are asking will show the entire location decision making process so we can see what went wrong. However those issues should be placed in a new issue and not mentioned under an enhancement request.

energywave commented 3 years ago

I managed to do some tests. I can confirm that the latest Android app is not bouncing anymore, so that's now ok, good work! I'm still doing automations for detecting SSID changes to speed-up state change in device_tracker (that's working excellently!) but I wonder why not to implement SSID binding to specific zones configured in Home Assistant. You could do that directly from zones editor in Home Assistant and from the app enforce zone switch when that specific SSID is connected and not_home when a specific SSID is disconnected (this last could be an option...) I think that would be a wonderful addition, I know that because I'm doing it manually with automations and set_state script. Thank you however for the wonderful work, I love the app!

stale[bot] commented 2 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment πŸ‘ This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

INVADIA666 commented 2 years ago

guys I'm reading this topic of SSID and I'm seting up a presence automation based on SSID change as trigger using some conditions as state SSID ( my wifi network ) when I try to make a new automation with the condition state : SSID not connected , the condition is wrong , I don't know if I'm putting the state wrong , I've tried 'not connected' , "not_connected " , I also checked the developer tool to confirm the state of the SSID and it shows as Not connected , I copy and paste that and the automation doesn't go thru the condition. I guess the state of the condition is wrong, I don't know what else to put to make it work .

SSID not connected is what's left to complete my presence automation . can anyone help me ?

Im new with HA

energywave commented 2 years ago

SSID not connected is what's left to complete my presence automation . can anyone help me ?

In this blog post of mine I give you an alegant solution that can help you in that. You only have to translate from Italian to English. Hint: the exact value for not connected wifi is "<not connected>"

jubie25 commented 10 months ago

Using the location feature is vital to many services around home automation. But as long as it drains the battery in such a heavy manner it's not possible to use it seriously and continuos. I sympathy with the idea to switch off geo location reads in the app while being in predefined SSID ranges where one can associate preselected geo information. Because this gets more and more important to services I think we should have at least a schedule for implementation (knowing that you are all volunteers spending their time to create such wonderful software!)

dshokouhi commented 10 months ago

I think we should have at least a schedule for implementation

Sorry we don't give any ETA people will work on whatever it is they want whenever they want.

sanzoghenzo commented 7 months ago

For those who come here in search of a solution/workaround, this is the automation that works for me (thanks to @energywave for his article)

alias: Wifi device tracker
description: "Changes the device tracker location based on the wifi connection"
trigger:
  - platform: state
    entity_id:
      - sensor.YOUR_PHONE_wifi_connection
      # you can add as many phones as you want
condition: []
action:
  - variables:
      ssid_zones:
        HOME_SSID: home
        WORK_SSID: work
        # and so on...
  - service: device_tracker.see
    metadata: {}
    data:
      dev_id: "{{ trigger.from_state.object_id }}"
      location_name: "{{ ssid_zones.get(trigger.to_state.state, 'not_home') }}"
mode: single

Obviously you need to change the uppercase bits with your values

energywave commented 7 months ago

Thank you @sanzoghenzo! By using YAML syntax is so clearer, good work! Just wanted to add that the is not even needed as you used (damn what a good solution it is!) the get method with the corresponding default value πŸ˜‰ But that remains a workaround. I continue to dream of seeing such an option in the app... With some more sophisticated parameters to filter odd conditions (like short wifi disconnection)

sanzoghenzo commented 7 months ago

Just wanted to add that the is not even needed as you used (damn what a good solution it is!) the get method with the corresponding default value πŸ˜‰

Great catch, I updated the code removing the <not connected> (the markdown renderer swallowed your text between angled brackets πŸ˜‰ ) item from the dictionary πŸ‘

alex3305 commented 3 months ago

@energywave @sanzoghenzo Thank you both for the initial automation (idea) and improvement. I also added a slight improvement, so that the sensor is created at Home Assistant startup:

- id: device_tracker_from_wifi
  alias: Device Tracker - From App Wifi Sensor
  variables:
    ssid_zones:
      HOME_SSID: home
      ANOTHER_HOME_SSID: home
      WORK_SSID: work
      # and so on...
  trigger:
    - id: update
      platform: state
      entity_id:
        - sensor.YOUR_PHONE_wifi_connection # Android sensor variant
        - sensor.YOUR_PHONE_ssid            # iOS sensor variant
        # and so on...
    - platform: homeassistant
      event: start
  action:
    - if:
        condition: trigger
        id: update
      then:
        - variables:
            dev_id: "{{ trigger.from_state.object_id }}"
            location_name: "{{ ssid_zones.get(trigger.to_state.state, 'not_home') }}"
      else:
        - service: device_tracker.see
          data:
            dev_id: YOUR_PHONE_wifi_connection
            location_name: "{{ ssid_zones.get(states('sensor.YOUR_PHONE_wifi_connection'), 'not_home') }}"
        - service: device_tracker.see
          data:
            dev_id: YOUR_PHONE_ssid
            location_name: "{{ ssid_zones.get(states('sensor.YOUR_PHONE_ssid'), 'not_home') }}"
    - service: device_tracker.see
      data:
        dev_id: "{{ dev_id }}"
        location_name: "{{ location_name }}"

This can also easily be expanded with cooldown periods as suggested by @energywave:

  trigger:
    - id: update
      platform: state
      entity_id:
        - sensor.YOUR_PHONE_wifi_connection
      to: 'home'
    - id: update
      platform: state
      entity_id:
        - sensor.YOUR_PHONE_wifi_connection
      not_to: 'home'
      for:
        seconds: 30

Although a bit more verbose, this should probably provide you with the flexibility that you need (if at all) πŸ˜‰ .