Help in track my car position

Hi,

I just noticed that Android App added the bluetooth sensor so I started to define a way to track where my car is based on my mobile position and store it to make it persistend during reboot.

This is what I’ve done so far based on others solution found in the forum:

automation:

  - id: grab_position_from_marco
    alias: Posizione Renata da Marco
    initial_state: true 
    trigger:
    - platform: template
      value_template: >
        {% if
        (is_state_attr('sensor.mi_6_bluetooth_connection', 'connected_paired_devices', '74:95:EC:0A:9A:AA')) %}
        true
        {% endif %}
    mode: queued
    action:
      repeat:
        while:
          - condition: template
            value_template: >
              {% if
              (is_state_attr('sensor.mi_6_bluetooth_connection', 'connected_paired_devices', '74:95:EC:0A:9A:AA')) %}
              true
              {% endif %}
        sequence:
          - service: notify.mobile_app_mi_6
            data:
              message: "request_location_update"
          - service: device_tracker.see
            data_template:
              dev_id: renata
              host_name: 'Renata'
              source_type: gps
              mac: '74:95:EC:0A:9A:AA'
              location_name: "{{ states('sensor.mi_6_geocoded_location') }}"
              gps_accuracy: "{{ states.person.marco.attributes.gps_accuracy }}"
              gps:
              - "{{ state_attr('person.marco', 'latitude') }}"
              -  "{{ state_attr('person.marco', 'longitude') }}"
          - delay:
              minutes: 10

This worked once (device_tracker was created) but then nothing.

For storing I’ve tried to “recycle” a solution found on another post but it seems that “value_template: {{ trigger.to_state.state }}” is wrong. But how to allow this automation to store every position saved regardless of the state?


variable:
          car_tracker_backup:
            restore: true
            value: home
            attributes:
              friendly_name: 'Car tracker backup'
        
automation:
        
          - id: backup_tracker_data
            alias: Backup custom device trackers
            description: Use a variable to persist custom device tracker data across resets
            trigger:
            - entity_id: device_tracker.renata
              platform: state
            condition: []
            action:
            - service: variable.set_variable
              data:
                variable: car_tracker_backup
                value_template: {{ trigger.to_state.state }}
                attributes_template: >
                  {
                    "source_type": "{{ trigger.to_state.attributes.source_type }}",
                    "latitude": "{{ trigger.to_state.attributes.latitude }}",
                    "longitude": "{{ trigger.to_state.attributes.longitude }}",
                    "gps_accuracy": "{{ trigger.to_state.attributes.gps_accuracy }}",
                    "host_name": "{{ trigger.to_state.attributes.friendly_name }}"
                  }
        
          - id: restore_trackers_on_startup
            alias: Restore custom device trackers
            description: Restore data for custom device trackers on startup
            trigger:
            - event: start
              platform: homeassistant
            condition: []
            action:
            - service: device_tracker.see
              data_template:
                dev_id: car
                host_name: "{{ state_attr('variable.car_tracker_backup', 'host_name') }}"
                location_name: "{{ states('variable.car_tracker_backup') }}"
                gps:
                - "{{ state_attr('variable.car_tracker_backup', 'latitude') }}"
                - "{{ state_attr('variable.car_tracker_backup', 'longitude') }}"
                gps_accuracy: "{{ state_attr('variable.car_tracker_backup', 'gps_accuracy') }}"

Thank you in advance to all the hints and suggestions!

I am not seeing that. What version of the app are you in?

I have the beta :wink:

1 Like