Problem with proximity automation, i need your help [SOLVED]

ok now try this

- alias: 'Phone battery low'
  trigger:
    platform: numeric_state
    entity_id: sensor.battery
    above:1
    below: 100
  condition:
    condition: state
    entity_id: device_tracker.xxxxxx
    state: 'home'
  action:
    service: tts.google_say
    entity_id: media_player.home_group
    data_template:
      message: "Your phones batterylevel is at {{  states.sensor.battery.state }} percent. Dont forget to charge your phone."

@Rodolfo_Vieira It tried your suggestion with the boolean. Did not work.

I was thinking; the source of the sensor.battery is a httppost command sent every 15 minutes from my phone via Tasker. This means the sensor isn’t there on HASS restart at first (it takes max. 15 minutes for it to be there). Could it be that the automation isn’t initialized therefore (allthough there are also no errors in my logfile and the automation does show up in my frontend and can be activated manualy)?

ok, do you have a android phone right?
if yes… install the app called GPSlogger, this app is amazing, much better the owntracks, and give the possibilty to know your battery status each one minute.
i use it, do you want a try? if yes, i give you the configuration.

Thanks, installing right now :slight_smile:

Update: which one? there are several “GPS Logger” apps

gps logger author Mendhak

after instaled go to setting /logging details/ LOG TO CUSTOM URL and put

http://YOUR_DOMAIN_OR_IP/api/gpslogger?latitude=%LAT&longitude=%LON&battery=%BATT&device=NAME_YOUR_DEVICE&accuracy=%ACC&api_password=YOUR_PASS_API

3 Likes

From my HASS?

1 Like

after that…

device.tracker.yaml

- platform: gpslogger

groups.yaml
- sensor.phone_battery

sensors.yaml

- platform: template
  sensors:
    phone_battery:
      friendly_name: 'status battery'
      value_template: '{{ states.device_tracker.YOUR_DEVICE_NAME.attributes.battery|float }}'
      unit_of_measurement: "%"
      entity_id: 
       - device_tracker.YOUR_DEVICE_NAME
2 Likes

yes, from your HAss

Thanks for this; I’ve been planning on trying out GPSLogger, even though I’m not having any issues getting my battery levels. I was hoping it was better than owntracks, so having this set up info is a huge help.

Thanks again!

2 Likes

@Rodolfo_Vieira working great, thanks!

Doesn’t it drain your battery?

it spends little. I mean … for my daily use, it does not make a difference.
Now you want help with automation, or you know how to do it?

I think I can manage it, I’ll let you know.
Thanks a lot for your help!

1 Like

try this first…

- alias: 'test'
  trigger:
    platform: numeric_state
    entity_id: sensor.phone_battery
    above: 30
    below: 100
  action:
    service: homeassistant.turn_on
    entity_id: input_boolean.working

Pff, still not working. Kinda tired of it right now. Will do some further investigation tomorrow.

sorry but, i did some tests now with this config.

- alias: 'test'
  trigger:
    platform: numeric_state
    entity_id: sensor.phone_battery
    above: 1
    below: 100
  action:
    service: homeassistant.turn_on
    entity_id: input_boolean.working

and works fine.

you need restart HA, after that go to the android mobile and force update manually, then you see your value battery on HA, and if you go to the DEV-TOOLS (states) you see input_boolean.working ON
If this step works, the problem is other…

@Rodolfo_Vieira & @Bob_NL I think you guys are missing one big thing in your logic for using the numeric_state triggers! your tests will not work.
the below and the above part of the triggers are the thresholds for when the automation should be triggered, but only once when the state change actually passes these thresholds.
so let’s say you use below: 50 as threshold for the automation. when you start HASS and the battery level is 100%, you won’t get a message immediately. as the day passes and your battery drains, you’ll get the message as soon as HASS detects a new value for the battery that is below 50 when it was greater than 50 before the state change happened. now let’s say you would have started HASS with your battery level at 40%. HASS wouldn’t send you a message, because the initial state is already below 50 and you never passed that threshold. You would have to charge your phone first until the battery (in HASS) would be above 50 and then it will send a message if your battery is depleting once again until it passes that threshold going down.

also @Rodolfo_Vieira I helped developing the proximity component when it first was released. your logic for the proximity component is also wrong: the state of the proximity component is in kilometres, not in metres. so the threshold below: 100 will only trigger if all devices were all further than 100km away from home after starting HASS
the automation for 100m would be:

alias: "send message me when i am less 100 meters of my house"
trigger:
  - platform: numeric_state
    entity_id: proximity.home
    value_template: '{{ states.proximity.home.state | float }}'
    below: 0.1
3 Likes

@Bart274 I see, thanks for your detailed explanation. If I understand correctly, it should trigger if I set the trigger for every state change and I use conditions in which I configure the above and below values, correct? The downside would be that it will trigger at every percentage drop.

@Bob_NL you misunderstood. it’s best just to use these numeric_state triggers, but then they would only trigger when passing the threshold, so for testing you need to wait until the state surpasses these thresholds.

Hi @Bart274 I seem to have the problem and nothing in this post really worked.

Looking at @treno post : Trigger numeric_state below value not firing

I figure out proximity state is not correctly configured as a numeric_state
The strange thing is
{{states.proximity.XXXXX.state}} gives the correct distance
but
{{states.proximity.XXXXX.state > 0}} gives an error

It is also strange that the function “above” seem to work but Not “below”.

Does anyone knows a solution to this problem?

Hi everyone.

This is the only way I mad it work.

The distance set here is 200 m
Since the below the proximity function doesn’t work because it is not recognized as a numeric_state. the Template way seems to be the only way for now.

The conditions are not necessary but avoid false trigger

- id: zonexxxx detect
  alias: M on his way to zoneXXXX
  trigger:
      platform: template
      value_template: "{% if states.proximity.zoneXXXX.state | float < 200 %} true {% endif %}"
  condition:
      condition: and
      conditions:
        - condition: state
          entity_id: device_tracker.iphone
          state: 'not_home'
        - condition: template
          value_template: '{{ states.proximity.zoneXXXX.attributes.dir_of_travel == "towards" }}'
  action:
     - service: notify.ios_iphone
       data:
         title: "going zoneXXXX"
         message: "almost zoneXXXX  !!"

1 Like