#Tinkerer, following on about the PSA Car

1 messages ยท Page 1 of 1 (latest)

sage wing
#

What do you mean "variables"?

plush herald
#

In the PSA Car Controller it pulls the car last location, i can see in the plugin where the car is right now, so it seems to have that information. I just need to create a connection between them

sage wing
#

What do you mean plugin?

#

Do you mean the add-on?

#

If yes, whenever you respond, then you need to check if the API provides that location

#
    resource: http://IPofTheSoftware:5000/get_vehicleinfo/YourVIN?from_cache=1
#

If that doesn't show it then there's nothing you can do

plush herald
#

The Add-On PSA Car Controller (plugin) provides on a map where the car is

sage wing
#

That's not a plugin

#

There's no such thing as plugins

#

They're called add-ons

#

Yes, the words you use matter ๐Ÿ˜‰

plush herald
#

Okay so now we've confirmed i'm taking about the add-on and not plugin, is there a way?

sage wing
plush herald
#

I need to find out how it descripes that geo-location and then i can (assumably) create a sensor for it?

sage wing
#

Yes, though it's not going to be trivial

#

First you need to get the data

#

Then you'll have to create a dummy device_tracker and use the device_tracker.see service or create an MQTT device tracker and publish the location to MQTT

plush herald
#

If i look back at the github i should be able to go into the PSA Car Controller and find the location call and what its assigned too?

sage wing
#

Click that ๐Ÿ˜‰

plush herald
#

I can see a last_position sensor in there

sage wing
#

And does that have a lat and long, or a word, or...?

plush herald
#

Co-ords 0,1,2 with what looks like lat/long

#

So yes

sage wing
#

Then you'll have to create a dummy device_tracker and use the device_tracker.see service or create an MQTT device tracker and publish the location to MQTT

plush herald
#

Okay i'll go look it up and see what i can do

sage wing
#
  - service: device_tracker.see
    data:
      dev_id: "car_gps"
      gps_accuracy: "10"
      gps:
        - "{{ latitude template }}"
        - "{{ longitude template }}"
#

Having created car_gps in known_devices.yaml and restarted HA

#
car_gps:
  icon:
  mac:
  name: car gps
  picture:
  track: true
plush herald
#

Won't it need to call the information from the url?

#

"last_position": {"type": "Feature", "geometry": {"coordinates": [-1.21465, 54.55443, 29.0], "type": "Point"}

sage wing
#

Ok... you need a sensor with the lat and long

#

There is no restful device trackerr

#

So, baby steps

#

First you need to get the data

#

Do that

plush herald
#

Okay so if i stick this in the sensors.yaml

    name: corsa_e
    resource: http://censor:5000/get_vehicleinfo/censored?from_cache=1
    scan_interval: 60
    timeout: 30
    value_template: 'OK'
    json_attributes:
    -last_position
- platform: template
    sensors:
    corsa_e_latitude:
    friendly_name: "Latitude"
    value_template: '["last.position"]["geometry"]["coordinates"]["0"]'
    sensors:
        corsa_e_longitude:
        friendly_name: "Longitude"
        value_template: '["last.position"]["geometry"]["coordinates"]["1"]'```
#

That hopefully will get the data from the json

#

then i can use the corsa_e_latitude in place like this

    data:
      dev_id: "car_gps"
      gps_accuracy: "10"
      gps:
        - "corsa_e_latitude"
        - "corsa_e_longitude"```
#

Would that work?

sage wing
#

No

#

First, you need actual templates in the service call

#

Second, you've mashed a template sensor and rest sensor together without understanding what's going on

plush herald
#

but i think i'm starting to understand how it work (a little)

sage wing
#
  - platform: template
    sensors:
      corsa_e_latitude:
        friendly_name: "Corsa E Lat"
        value_template: '{{ states.sensor.corsa_e.attributes["last.position"]["geometry"]["coordinates"]["0"] }}'
      corsa_e_longitude:
        friendly_name: "Corsa A Long"
        value_template: '{{ states.sensor.corsa_e.attributes["last.position"]["geometry"]["coordinates"]["1"] }}'
#

(probably)

#

Then

  - service: device_tracker.see
    data:
      dev_id: "car_gps"
      gps_accuracy: "10"
      gps:
        - "{{ states('sensor.corsa_e_latitude') }}"
        - "{{ states('sensor.corsa_e_longitude') }}"
#

(probably)

#

Remember that last piece is a service call that doesn't go in the sensor definition

plush herald
#

Okay, great help me understand this... how does HA know where to find the last.position, do it just know that because its been called from else where in the yaml

sage wing
#

You'll use that service in an automation that's called when the lat/long changes

sage wing
#

You may have to add last.position to the JSON attributes

plush herald
#

Just restarted HA after adding the sensor but its showing as status Unavaliable

sage wing
#

Go back and do all the troubleshooting steps again

plush herald
#

Got it pulling the information now, templates channel helped me. Thanks again for all the help

#

I'm trying to add - service: device_tracker.see data: dev_id: "car_gps" gps_accuracy: "10" gps: - "{{ states('sensor.corsa_e_latitude') }}" - "{{ states('sensor.corsa_e_longitude') }}" to a yaml file but its asking for a platform

sage wing
#

Remember that last piece is a service call that doesn't go in the sensor definition
You'll use that service in an automation that's called when the lat/long changes

#

(from above)

plush herald
#

I've created the known_devices.yaml, do i need to reference that in the configuration.yaml?

sage wing
#

No

#

Just write that automation, triggered by the state change of those two sensors

plush herald
#

I'm creating the automation now...
When corsa e lat or corsa e long changes state or any attributes as the 'When'
Then do ' Call a service 'Device Tracker: See'

#

Manually ran the automation and got this error must contain at least one of mac, dev_id

pale sphinxBOT
#

Sadly we're not mind readers (any more anyway, not after the last time we tried). Please share the YAML and any errors so we can see what you've done.

plush herald
#
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.corsa_e_lat
      - binary_sensor.corsa_e_long
condition: []
action:
  - service: device_tracker.see
    data: {}
mode: single```
sage wing
#

Ok...

#

Did you look at that before posting it?

plush herald
#

Its my first time creating a automation (hell its my first time for a lot of things today)

sage wing
#

Did you look at that before posting it?

#

Did you compare the service call to what I posted? Hell, to what you posted?

plush herald
#

I used the visual builder when i did, maybe i should stick to the yaml file and i might have seen something

sage wing
#
  - service: device_tracker.see
    data: {}

vs

  - service: device_tracker.see
    data:
      dev_id: "car_gps"
      gps_accuracy: "10"
      gps:
        - "{{ states('sensor.corsa_e_latitude') }}"
        - "{{ states('sensor.corsa_e_longitude') }}"
plush herald
#

Okay, lets go back to me being an idoit here as I don't understand. I created the known_devices.yaml and put the - service: device_tracker.see data: dev_id: "car_gps" gps_accuracy: "10" gps: - "{{ states('sensor.corsa_e_latitude') }}" - "{{ states('sensor.corsa_e_longitude') }}" code into it

sage wing
#

What?

#

Dude

#

Dude!

plush herald
#

Having created car_gps in known_devices.yaml and restarted HA

sage wing
#
car_gps:
  icon:
  mac:
  name: car gps
  picture:
  track: true
sage wing
#
car_gps:
  icon:
  mac:
  name: car gps
  picture:
  track: true
plush herald
#

Ah so you meant the top part in the known_devices not the bottom part

sage wing
#

Other way around

plush herald
#

Ignore me i read the whole thing wrong!

#

Sorry absolute idoit here

sage wing
#

's fine

#

Just ... start paying attention when the error appears

#

When that happens, look at what I wrote, and what you have

plush herald
#

Okay so... i don't get this wrong and look even worse... i've gone into the automation (yaml editor) should i just copy and paste what you have or does it need the tigger part as well. Like this ```alias: Corsa E GPS Change
description: ""
trigger:

  • platform: state
    entity_id:
    • binary_sensor.corsa_e_lat
    • binary_sensor.corsa_e_long
      condition: []
      action:
  • service: device_tracker.see
    data:
    dev_id: "car_gps"
    gps_accuracy: "10"
    gps:
    - "{{ states('sensor.corsa_e_latitude') }}"
    - "{{ states('sensor.corsa_e_longitude') }}"
    mode: single```
sage wing
#

Close

#

binary_sensor.corsa_e_lat is wrong

#

Those have to be sensor

#

binary_sensor.corsa_e_lat is on/off

#

The templates have to match the entity

plush herald
#

and of course the gps coordinates would never be 1 or 0

#
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.corsa_e_lat
      - sensor.corsa_e_long
condition: []
action:
  - service: device_tracker.see
    data:
      dev_id: "car_gps"
      gps_accuracy: "10"
      gps:
        - "{{ states('sensor.corsa_e_latitude') }}"
        - "{{ states('sensor.corsa_e_longitude') }}"
mode: single```
sage wing
#

Nope

#

sensor.corsa_e_lat vs sensor.corsa_e_latitude

#

(etc)

plush herald
#

I can't see a way for it to accept vs in the yaml... just errors

sage wing
#

Dude

#
sensor.corsa_e_lat

or

sensor.corsa_e_latitude
#

one's wrong

pale sphinxBOT
sage wing
#

Look there

plush herald
#

Amusing i wasn't answering here from the same network as my home assistant panel, but i worked out where you wanted me to go!

#
Corsa E Lat
    -1.21465     friendly_name: Corsa E Lat
sensor.corsa_e_longitude
Corsa E Long
    54.55443     friendly_name: Corsa E Long```
#

Wiped out the _ in the copy and paste

#
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.corsa_e_latitude
      - sensor.corsa_e_longitude
condition: []
action:
  - service: device_tracker.see
    data:
      dev_id: car_gps
      gps_accuracy: "10"
      gps:
        - "{{ states('sensor.corsa_e_latitude') }}"
        - "{{ states('sensor.corsa_e_longitude') }}"
mode: single
#

I saw what i did wrong! I removed the binary. from the start of the entity_id and didn't think the none binary sensors had a wrong name

#

different name ( i need some sleep obviously!)

sage wing
#

Now try that and see if it works

pale sphinxBOT
#

To test an automation there's three stages you can follow. Testing the action, the condition and action, and the whole automation:

  1. Use Configuration -> Automations to find the automation and then select Run in the three dots menu. If this fails your problem is in the action: section, and details should be found in your log file
  2. Use Developer tools -> Services and call automation.trigger on the automation with skip_condition: false. If the first passes but this fails then the problem is in your condition: block
  3. Use Developer tools -> States to find the trigger entity, click the name, then change the state (at the top) to something that'll trigger the automation before pushing Set State. If this fails then the problem is with your trigger: section, or the automation is turned off (you can check that in Automations, automations that are turned off will show Disabled)

You can also see this section in the docs about testing and automation traces.

plush herald
#
Result:

params:
  domain: device_tracker
  service: see
  service_data:
    dev_id: car_gps
    gps_accuracy: '10'
    gps:
      - -1.21465
      - 54.55443
  target: {}
running_script: false```
#

ran no problem! Phew

sage wing
#

Now look at States for device_tracker.car_gps

plush herald
#

I've got it on the map! Discovered something the 1 and 0 should be the other way round as the car is the middle of the Indian Ocean according to the map ๐Ÿ˜›

#

Just off the coast of the Seychelles

#

Sorted. I really appreciate all your help Tinkerer

#

Sent donation your way

#

If i want to add an image of the car to the map, i assume i just edit the known_devices.yaml and add the location of the file to the picture: line?

sage wing
#

As a URL path

plush herald
#

i've created www folder and uploaded the file to there so it'll just be /www/corsa.jpg

sage wing
#

No

pale sphinxBOT
plush herald
#

Okay so i have to use the full url, thanks

sage wing
#

No

plush herald
#

I'm reading the wrong thing then... 5 minutes

sage wing
#

/local/corsa.jpg

plush herald
#

I'm assuming if i want too do this for the cupra its pretty similar (however it already has a device_tracker.cupra_born_tracker)

sage wing
#

Yes

plush herald
#

Cool one last thing, went i reboot HA it looses the car position. I manually run the automation and it comes back, anyway to make it run more frequently or on restart?