ESPresense / ad-espresense-ips

DEAD: See https://github.com/ESPresense/ESPresense-companion
63 stars 9 forks source link

how to use #2

Open corgan2222 opened 3 years ago

corgan2222 commented 3 years ago

Hello, as answer to your comment https://github.com/mKeRix/room-assistant/issues/842#issuecomment-922391919 I'm looking into this, but I'm not sure what to do with this app. What's the out coming from this?

DTTerastar commented 3 years ago

You give it the locations of your base stations and it tries to calculate where the tracker is in relation to those base stations. It could be overlayed on a floor plan so you could see where stuff is. Or you could tell if your inside your house, or outside.

michaeldvinci commented 3 years ago

Could you help explain what the third number in the plot coordinates is?

garage: [0, 8, 0.4]
office: [5, 1.5, 0.5]
family: [0, 0, 0]

How did you define the the .4, .5, and 0 as they are height/z, right?

DTTerastar commented 3 years ago

Z is elevation in meters

On Sun, Sep 19, 2021 at 12:20 PM Michael Vinci @.***> wrote:

Could you help explain what the third number in the plot coordinates is?

garage: [0, 8, 0.4] office: [5, 1.5, 0.5] family: [0, 0, 0]

How did you define the the .4, .5, and 0 as they are height/z, right?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ESPresense/ad-espresense-ips/issues/2#issuecomment-922499294, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALMBSOCJM6YYBYZGNK36I3UCYETFANCNFSM5EJXDUOQ .

DTTerastar commented 3 years ago

Yeah one thing I've noticed is because antennas work better when higher up, trilateration for height doesn't work well yet. I think trying to put all base stations at the same height would be better to start with.

DTTerastar commented 3 years ago

Hello, as answer to your comment mKeRix/room-assistant#842 (comment) I'm looking into this, but I'm not sure what to do with this app. What's the out coming from this?

The idea is we can deduce the location even if there isn't a base station in that room. So you could put 4 devices on the four corners of your house and it can find where it must be based on the distances measured from the 4 points. In practice the more base stations the better, so i'd still have 6 or so, but we should be able to show the location +-1m in your house if it works.

Alfiegerner commented 3 years ago

Hi @DTTerastar , probably being a bit dense here but still not getting it.

So the base station locations are defined as per:

garage: [0, 8, 0.4]
office: [5, 1.5, 0.5]
family: [0, 0, 0]

How do define the perimeters of the rooms?

Any idea how you'd model an L shaped house? Thanks!

DTTerastar commented 3 years ago

That's the coordinates of the base station only. I don't yet have any perimeters of rooms. That would be a later step once we get the positioning right. The code is really very dumb so far, all it does is trying and work out the most likely position by taking all fixes (distances to base stations) and base station locations and minimizing the total error based on a guess of where the device is. It outputs both the raw x,y,z as as well as a latt, long, and altitude. The latter is just the former plus the latt, long, and elevation specified in your appdaemon.yaml

Alfiegerner commented 3 years ago

Thanks makes sense now, I'll plug it in and have a play and let you know how I go.

Alfiegerner commented 3 years ago

Got it up and running, definitely lots of potential!

I found moving around the house would cause the 'holding' of old values, as we don't expire distances once we're out of range. I added a noddy timeout which helped a lot:


...
        dr["updated"] = time.time():
....
                if ("distance" in device["rooms"][r]) and (time.time() - device["rooms"][r]["updated"] < 10):
                    distance_to_stations.append(device["rooms"][r]["distance"])
                    stations_coordinates.append(device["rooms"][r]["pos"])

Something a bit more sophisticated like weighting the values might help but that's getting a bit outside my ken.

It would be nice to see which stations are currently 'fixed' to help debug - i'm a python novice and couldn't work out how to get the room name so gave up on that.

In terms of accurancy I can definitely see a case with this for adding that Android setting to specify tx power, I'll see if I can come back to that. I'm using room-assistant for base stations at the moment while I wait for some esp32s to arrive, and found that the ability to override transmission power increased accuracy a lot.

Thanks @DTTerastar for this, nice bit of work.

DTTerastar commented 3 years ago

Yeah, when I originally wrote it I didn't set the maxDistances very low so all nodes would send a value. It's annoying that you need maxDistances to make Home Assistant work right, but it kills this use case. That's part of why I send both room and devices. I want to make one the unfiltered view of all data, and the other is specifically for HA. Either that or just use the AppDaemon app to do the job of mqtt room since it doesn't really work all that well. Oh and if you're not using ESPresence you don't have the really nice kalman filtering, right?

Alfiegerner commented 3 years ago

I think last updated filtering instead of Max distance would be useful- what I saw without it was that old values would contaminate current position whether that testing was high or low. I have 10 base stations over a fairly large area so it's not unusual to walk out of range of a device while it's still reporting as 'close'.

Oh and room assistant uses Kalman filtering too, will be interesting to see how well the espsence and room assistant stations play together.

Would you happy with me doing a small PR to add an 'updatedWithin' property, defaulting to existing behaviour of not being used?

ee02217 commented 3 years ago

Should I see a new topic generated by this appdaemon? How do I confirm this is working fine?

(Sorry for the probably dumb question)

DTTerastar commented 3 years ago

It reads from espresense/rooms and writes to espresense/ips and espresense/location.

ee02217 commented 3 years ago

It doesn't show up for me. But I don't see any error in logs :(

DTTerastar commented 3 years ago

Can you post the redacted apps.yml?

ee02217 commented 3 years ago

Here you go. I still dont have the 3rd base station, maybe that is the problem. But I expected some errors at least.

~/appdaemon$ more appdaemon.yaml

appdaemon:
  time_zone: Europe/Lisbon
  latitude: 38.XXXXXXX
  longitude: -9.YYYYYY
  elevation: 60
  plugins:
    HASS:
      type: hass
      ha_url: "http://192.168.1.XXX:8123"
      token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
      app_init_delay: 30
      appdaemon_startup_conditions:
        delay: 30
    MQTT:
      type: mqtt
      client_host: 192.168.1.XXX
      namespace: mqtt
      birth_topic: appdaemon
      will_topic: appdaemon

http:
  url: "http://192.168.1.XXX:5050"
admin:
api:
hadashboard:

logs:
  main_log:
    filename: /home/ee02217/appdaemon/logs/appdaemon.log
  access_log:
    filename: /home/ee02217/appdaemon/logs/access.log
  error_log:
    filename: /home/ee02217/appdaemon/logs/error.log
  diag_log:
    filename: /home/ee02217/appdaemon/logs/diag.log
    log_generations: 5
    log_size: 1024
    format: "{asctime} {levelname:<8} {appname:<10}: {message}"
  test_log:
    name: TestLog
    filename: /home/ee02217/appdaemon/logs/test.log

ee02217@NUC:~/appdaemon/apps$ more apps.yaml

ESPresenseIps:
  module: espresense-ips
  class: ESPresenseIps
  pluggins:
    - HASS
    - MQTT
  rooms:
    livingroom: [1, 0.5, 0]
    bedroom: [16, 3.5, 0]
  devices:
  - id: apple:ZZZZ:X-YY
    name: AppleWatch_Sergio
    timeout: 30
    away_timeout: 120
DTTerastar commented 3 years ago

Ahh yeah, that's it. From the README: This requires at least 3 ESPresense nodes that can get a "fix" on the particular device. The more devices the better. To get a decently accurate position you need at least 5 or 6. But this can find the location of something even if the particular room doesn't have a base station (You can put nodes on the perimeter of your house instead of the "center" of rooms). We need futher work to actually determine if the item is actually in a particular room (we'll need some kind of floorplan).

DTTerastar commented 3 years ago

Trilateration requires 3 to do be able to find the location. It really needs more like 4 or 5 to do a decent job with all of error present in rssi measurements.

ee02217 commented 3 years ago

Oh man... really sorry! I just expected some error or something (this is my first adventure in the appdaemon)

Just a final confirmation, I read the above conversation, and I'll need to increase the Max Distance to the max?

DTTerastar commented 3 years ago

I don't log anything for that case atm because it happens pretty often and would just clog the logs. I could add a periodic stats print out to help people tho. Good idea.

DTTerastar commented 3 years ago

MaxDistance 0 does no filtering. Atm is does help to set the maxDistance higher than your otherwise would. This is all VERY beta. I'd like to make maxDistance only apply to the mqtt room topic and use another topic so we get all the data.

ee02217 commented 3 years ago

Completely understand. And very keen to help you test this. Already ordered two more esp32 :) Biggest problem where I’m from is that walls really mess up signals (concrete). I already have my home 3D map ready for experiences :D

DTTerastar commented 3 years ago

Completely understand. And very keen to help you test this. Already ordered two more esp32 :) Biggest problem where I’m from is that walls really mess up signals (concrete). I already have my home 3D map ready for experiences :D

Sweet! I need the help!

dmccabe79 commented 3 years ago

OK, maybe I need another cup of coffee before I attempt to wrap my head around this. So we're plotting X,Y,Z coordinates, I got that. How do I determine what is correct? How do I figure X and Y? Z is height in meters, but the others?

ee02217 commented 3 years ago

Has anyone noticed the amount of RAM this is using to bee quite high?

DTTerastar commented 3 years ago

OK, maybe I need another cup of coffee before I attempt to wrap my head around this. So we're plotting X,Y,Z coordinates, I got that. How do I determine what is correct? How do I figure X and Y? Z is height in meters, but the others?

X and Y are also meters. You gotta have a floor plan and measure where the base stations are in relation to each other.

DTTerastar commented 3 years ago

Has anyone noticed the amount of RAM this is using to bee quite high?

I haven't. Does it continuously increase like a memory leak?

dmccabe79 commented 3 years ago

OK, maybe I need another cup of coffee before I attempt to wrap my head around this. So we're plotting X,Y,Z coordinates, I got that. How do I determine what is correct? How do I figure X and Y? Z is height in meters, but the others?

X and Y are also meters. You gotta have a floor plan and measure where the base stations are in relation to each other.

Do you have a recommended means of doing this?

DTTerastar commented 3 years ago

I estimated mine using a thing like this: https://amzn.to/3uDLcLl

Eventually i'd like to have some sort of gps attachment, or phone app to figure it out.

dmccabe79 commented 3 years ago

I could probably figure it out by just walking the area. X and Y might be tricky to calculate. Z is the easy one

DTTerastar commented 3 years ago

I don't understand what you mean by calculate. Just pick a corner, call that 0,0 and measure the distance from there to the base station.

On Sat, Oct 2, 2021 at 8:14 PM dmccabe79 @.***> wrote:

I could probably figure it out by just walking the area. X and Y might be tricky to calculate. Z is the easy one

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ESPresense/ad-espresense-ips/issues/2#issuecomment-932838219, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALMBSPPMAHKGGZISK52WVLUE6N7RANCNFSM5EJXDUOQ .

dmccabe79 commented 3 years ago

If the distance is 5 meters... is that X? Then what is Y?

I don't understand what you mean by calculate. Just pick a corner, call that 0,0 and measure the distance from there to the base station.

On Sat, Oct 2, 2021 at 8:14 PM dmccabe79 @.***> wrote:

I could probably figure it out by just walking the area. X and Y might be tricky to calculate. Z is the easy one

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ESPresense/ad-espresense-ips/issues/2#issuecomment-932838219, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALMBSPPMAHKGGZISK52WVLUE6N7RANCNFSM5EJXDUOQ .

DTTerastar commented 3 years ago

x is the distance off one wall, y is the distance off the other.

+------------------------------------+
|                              
|
|
|
|  <- x- >         *
|                       
|                  ^
|                  y 
|                  v
+------------------------------------+
dmccabe79 commented 3 years ago

Perfect. Thanks.

I work in aviation. XYZ coordinates are way different to me. Thanks for the explanation.

michaeldvinci commented 3 years ago

Has anyone noticed the amount of RAM this is using to bee quite high?

I haven't. Does it continuously increase like a memory leak?

Mine's finally up and running, and my Pi4 4GB went from ~8% CPU usage to ~50% with AppDaemon running. I'm going to let it go overnight and see if it mellows out

DTTerastar commented 3 years ago

Oh this does use a ton of CPU. The multilateration is a lot of math, and python is a pig. Atm it does it for every single measurement which probably isn't right either. It should take probably wait 15 seconds before recalcing... Except when moving quickly... Then is should be more like every couple seconds.

nmajin commented 2 years ago

Couple questions...

  1. I know the room perimeter is still being worked out, but if I have all my ESP devices NOT in the center of the room, what should I put for values? I have 4 rooms and 4 devices I plan to setup
  2. Do we actually need to use this AppDaemon or could we setup each ESPresence with the measured "Maximum distance to report (in meters):" and use that instead?

Note: I have one ESPresense at the moment that I modified to 2 meters for one of my rooms and that works pretty good to determine if I am in that room or not

And bonus question...I assume that with multiple ESPresense capturing my watch (in this case) around the house (properly putting a device in all rooms) will update my watch to that room and only go into "not_home" when I am truly away from home? I am trying to use my watch as my main tracking device overall.

KuotenoAshiato commented 2 years ago

So for your first question: The room feature is exactly for the case of the ESPs not beeing in the center. Without the calculations of the AppDaemon, one esp can just work on its own. For it to approximately use the scale of the room, it is only configurable in the range. As youre increasing this range, youre increasing it into each direction. So, if you're having the device at an edge of one room and setting the range to the length of the other edge for full coverage, then you're expanding to that width aswell towards behind the edge, which ( in some cases) could be another room or outside.

The AppDaemon in that case uses position based calculations to get a hold of your positions between those ESPs that can see you at the same time. The more ESPs see you, the more accurate your position gets. The only problem with that is, that to determine a special room, you would need to have some case of coordinate based Floorplan to put the coordinates of your device in relation to the room it is in.

I made some changes to a fork of this project where I implemented the basic functionality of this feature, I'm still doing some testing tho, to get it more accurate, once I'm able to set up more devices

DTTerastar commented 2 years ago

Hearing you've forked this has made my day :) Thank you for helping! I've gotten a little burned out...

KuotenoAshiato commented 2 years ago

You're Welcome! I've searched for something like this for quite sometime. As soon as i get the time to measure the correct distances of each room, I'll try to improve the speed of the room recognition as with enough ESPs and a big enough room, the jitter of the coordinates shouldn't be that much of a Problem.

DTTerastar commented 2 years ago

Awesome! I got very disheartened when I realized "Areas" are not a concept AppDaemon supports or wants to support: https://github.com/AppDaemon/appdaemon/issues/505

mjcumming commented 2 years ago

I think the right way to do this is by training, Place a selection of ESP32's around your home. The number would depend on levels and square footage. Then create a list of rooms. Take your BT device and walk around each room and train the system on expected readings for each room. This would be the most robust solution versus manually trying to solve by triangulating.

DTTerastar commented 2 years ago

Yes, I think that could also work very well. I think BOTH should be tried. Having the exact coordinates would be awesome on a floorplan to find stuff tho :)

gravyflex commented 2 years ago

Z is elevation in meters

On Sun, Sep 19, 2021 at 12:20 PM Michael Vinci @.***> wrote:

Could you help explain what the third number in the plot coordinates is?

garage: [0, 8, 0.4] office: [5, 1.5, 0.5] family: [0, 0, 0]

How did you define the the .4, .5, and 0 as they are height/z, right?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ESPresense/ad-espresense-ips/issues/2#issuecomment-922499294, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALMBSOCJM6YYBYZGNK36I3UCYETFANCNFSM5EJXDUOQ .

I am a little confused with this. The elevation from the floor of the room to the height that the esp32 is at in meters?

Also, how do you account for the rooms in a multi story house? Would you need to do anything special?

DTTerastar commented 2 years ago

Basically since your "house" has a single elevation listed in hass and appdaemon, this z is just an offset from that elevation. If you put the elevation on your first floor, then make z 0 or the height off the floor. If you make the top of your house the elevation z's would all be negative. I picked the first method.

duceduc commented 2 years ago

I am getting this error when from appdaemon.

error: 2022-01-24 10:08:47.723331 INFO MQTT: Unable to decode MQTT message

This is what I have in these files. appdaemon.yaml

appdaemon:
  latitude: !secret home_latitude
  longitude: !secret home_longitude
  elevation: !secret home_elevation
  time_zone: Japan
  plugins:
    HASS:
      type: hass
      ha_url: http://192.168.1.20:8123
      token: !secret appdaemon_token
      namespace: default
    MQTT:
      type: mqtt
      client_host: 192.168.1.20
      namespace: mqtt
      birth_topic: appdaemon
      will_topic: appdaemon

http:
  url: http://127.0.0.1:5050
hadashboard:
admin:
api:

apps.yaml

ESPresenseIps:
  module: espresense-ips
  class: ESPresenseIps
  pluggins:
    - HASS
    - MQTT
  rooms:
    masterroom: [5, 4, 0.5]
    shionroom: [5, 4, 0.5]
    livingroom: [6, 10, 0.5]    
    kitchen: [3, 5, 0.5]
  devices:
  - id: roomAssistant:04ea2071-f457-46d3-97a1-xxxxx
    name: DucESPresense
    timeout: 30
    away_timeout: 120
  - id: roomAssistant:f7ae1827-e0c9-4900-b7e8-xxxx
    name: EriESPresense
    timeout: 30
    away_timeout: 120
  - id: apple:iphone7-1
    name: Shionisp
    timeout: 30
    away_timeout: 120
gravyflex commented 2 years ago

Does your MQTT server need auth?

duceduc commented 2 years ago

You mean does it require a username/ password? Yes, it does.

gravyflex commented 2 years ago

Your appdaemon.yaml is missing client_user and client_password under MQTT if I am seeing correctly.

duceduc commented 2 years ago

Yea, I just added these but still get same error. Do I need to restart HA since I added the ad-espresense-ips folder under apps folder? edited: Restarted HA just just for the sake of it, but no go. Still same error.

MQTT:
  type: mqtt
  client_host: 192.168.1.20
  client_user: !secret mqtt_user
  client_password: !secret mqtt_pass
  namespace: mqtt
  birth_topic: appdaemon
  will_topic: appdaemon

error:

2022-01-24 10:32:17.009236 INFO ESPresenseIps: Subscribing to topic espresense/rooms/masterroom
2022-01-24 10:32:17.017121 INFO MQTT: Topic espresense/rooms/masterroom already unsubscribed from
2022-01-24 10:32:17.024626 INFO ESPresenseIps: Subscribing to topic espresense/rooms/shionroom
2022-01-24 10:32:17.026891 INFO MQTT: Topic espresense/rooms/shionroom already unsubscribed from
2022-01-24 10:32:17.035383 INFO ESPresenseIps: Subscribing to topic espresense/rooms/livingroom
2022-01-24 10:32:17.037914 INFO MQTT: Topic espresense/rooms/livingroom already unsubscribed from
2022-01-24 10:32:17.047197 INFO ESPresenseIps: Subscribing to topic espresense/rooms/kitchen
2022-01-24 10:32:17.049573 INFO MQTT: Topic espresense/rooms/kitchen already unsubscribed from
2022-01-24 10:32:17.058345 INFO AppDaemon: App initialization complete
2022-01-24 10:33:16.773583 INFO MQTT: Unable to decode MQTT message
2022-01-24 10:33:16.884486 INFO MQTT: Unable to decode MQTT message
2022-01-24 10:33:17.150575 INFO MQTT: Unable to decode MQTT message