Ok, after a restart of HA the current values are shown again.
Does it work for you now? I get the same errors I did two days ago, and the password is still replaced with the random sting
Yes, I have turned off the debug info on the component so I can’t check the password issue.
Please help me with template.
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected char ‘‘’ at 23) for dictionary value @ data[‘sensors’][‘leaf_charge_time_1’][‘value_template’]. Got ‘“{{(0.24 * (100-states(‘sensor.xxxxx_charge’)|int)/6) | round(2)}}”’. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/
- platform: template
sensors:
leaf_charge_time_1:
entity_id: sensor.xxxxx_charge
friendly_name: “Leaf Charge Time (6000w)”
value_template: “{{(0.24 * (100-states(‘sensor.xxxxx_charge’)|int)/6) | round(2)}}”
unit_of_measurement: ‘Hours’
icon_template: mdi:timer
Try this, it’s all in the formatting, my fault for not using the code thingy.
- platform: template
sensors:
leaf_charge_time_1:
entity_id:
- sensor.xxxxx_charge
friendly_name: "Leaf Charge Time (6000w)"
value_template: "{{(0.24 * (100-states('sensor.xxxxx_charge')|int)/6) | round(2)}}"
unit_of_measurement: 'Hours'
icon_template: mdi:timer
same error
Configuration invalid CHECK CONFIG
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected char ‘‘’ at 23) for dictionary value @ data[‘sensors’][‘leaf_charge_time_1’][‘value_template’]. Got ‘“{{(0.24 * (100-states(‘sensor.xxxxx_charge’)|int)/6) | round(2)}}”’. (See ?, line ?). Please check the docs at Template - Home Assistant
- platform: template
sensors:
leaf_charge_time_1:
entity_id:
- sensor.xxxxx_charge
friendly_name: “Leaf Charge Time (6000w)”
value_template: “{{(0.24 * (100-states(‘sensor.xxxxx_charge’)|int)/6) | round(2)}}”
unit_of_measurement: ‘Hours’
icon_template: mdi:timer
it’s the single quotes in the value_template, change them for real single quotes, I don’t know what they are in your example (and mine as I cut and pasted yours).
If you like, cut and paste the following into the double quotes to replace the value_template.
{{(0.24 * (100-states('sensor.l333bond_charge')|int)/6) | round(2)}}
P.S. I also notice that the same quotes are in the next line, unit_of_measurements, heres another line to replace it.
unit_of_measurement: 'Hours'
P.P.S. Also your double quotes look off, try changing them.
Thanks for help. How can i add update button with last update attempt stamp.
Script
alias: Leaf Update
sequence:
- data:
' vin': HJFYAASD0U3678365
service: nissan_leaf.update
Input boolean
leaf_update:
name: "Leaf update"
initial: off
icon: mdi:clockwise
This is a great component! I’ve been waiting for this since we got our 2012 used Leaf this last year!
I’m working on an automation to remind my wife to plug in the car (as she often forgets) when she gets home. Basically the automation will wait until she is home for 10 minutes (with device tracker), trigger an update to Carwings, wait for it to finish and then do a Google TTS on our Sonos telling her that the car isn’t plugged in, how much charge and range is left.
Once I get it all working right I’ll share it with you all
The first part of the automation is to be able read the attribute of update_in_progress == true to flip an input boolean but can’t get this to work. Anyone know a solution or a better way to read this?
Thanks!
# --------------------------------------------------------------------------------
- alias: Leaf - Update Start
trigger:
- platform: template
value_template: "{{ states.sensor.leaf2012XXXXXX_charge.attributes.update_in_progress == 'true' }}"
- platform: template
value_template: "{{ states.sensor.leaf2012XXXXXX_range.attributes.update_in_progress == 'true' }}"
- platform: template
value_template: "{{ states.sensor.leaf2012XXXXXX_range_ac.attributes.update_in_progress == 'true' }}"
- platform: template
value_template: "{{ states.binary_sensor.leaf2012XXXXXX_charging_status.attributes.update_in_progress == 'true' }}"
- platform: template
value_template: "{{ states.binary_sensor.leaf2012XXXXXX_plug_status.attributes.update_in_progress == 'true' }}"
action:
- service: homeassistant.turn_on
data:
entity_id: input_boolean.leaf_updating
This is just a proposal, but if I understand your scenario you could do it all with just one automation.
- alias: Leaf - Check if car is plugged in when getting home and send notification to plug in if needed
trigger:
- platform: state
entity_id: device_tracker.xxx
state: 'home'
action:
## this is the delay you want before the update is triggered
- delay: '00:10:00'
## update the service
- service: nissan_leaf.update
data:
vin: 'xxxxxxx'
- wait_template: "{{ states.binary_sensor.leaf2012XXXXXX_plug_status.attributes.update_in_progress == 'true' }}"
## time to wait until the the update have started and the attribute have been changed, the 5 min is just a guess, could probably be shorter
timeout: '00:05:00'
## this to stop the automation if the status haven't been changed
continue_on_timeout: false
- wait_template: "{{ states.binary_sensor.leaf2012XXXXXX_plug_status.attributes.update_in_progress == 'false' }}"
## time to wait until the the update have completed and the attribute have been changed, the 5 min is just a guess
timeout: '00:05:00'
## this to stop the automation if the status haven't been changed, you can set this to true, but that doesn't make sense in your scenario
continue_on_timeout: false
## check if it is plugged in or not
- wait_template: "{{ states.binary_sensor.leaf2012XXXXXX_plug_status.state == 'off' }}"
timeout: '00:00:01'
## stop of car is plugged in
continue_on_timeout: false
## send the notification
- service: whatever notification service you are using to send notification
I don’t have this scenario setup myself, since we are having to cars we charge so it’s every other day for the charge. But I’m using the syntax in other automations and I find it quite useful, being able to make things a little easier without using input_booleans and several automations.
Thanks I’ll give that a try. It would be nice if this component had a specific sensor that would explicitly tell you when it is updating instead of having to look at attributes nested in the sensor directly. Maybe an enhancement?
Why don’t you just create a template sensor if you feel that there is a need for it?
First, thanks for a great component, nice to see it implemented in a release!
I’m having the same problem as smile with charge status not updating (I’ve never seen it change to charging):
I have a 2018 Leaf, so it uses the Nissan Connect. I can’t see any error messages in the log with regard to this issue. Mine is listed as a binary_sensor, not a switch, so that should be correct. Does the charge sensor work for you?
Awesome work - this works great!
I have two Leafs - how do I add both to the configuration.yaml?
I can add two this way:
nissan_leaf:
- username: "YOUR_USERNAME"
password: "YOUR_PASSWORD"
region: "YOUR_REGION"
- username: "YOUR_USERNAME"
password: "YOUR_PASSWORD"
region: "YOUR_REGION"
But I then get state duplicates and the 2nd vehicle never seems to populate with data.
I thought I’d add a couple of sensors, these will pull the time etc. from the updates and display in a nice format (I stole the code), and the last one will tell you if you’re updating now.
- platform: template
sensors:
leaf_next_update:
friendly_name: 'Leaf Next Update'
value_template: >
{%- macro suffix(d) %}
{%- set sfx = {1:'st',2:'nd',3:'rd'} %}
{{- 'th' if 11 <= d <= 13 else sfx.get(d%10, 'th') }}
{%- endmacro %}
{% set day = as_timestamp(states.sensor.xxxxxxx_charge.attributes.next_update) | timestamp_custom('%a') %}
{% set date = as_timestamp(states.sensor.xxxxxxx_charge.attributes.next_update) | timestamp_custom('%d') |int %}
{% set time = as_timestamp(states.sensor.xxxxxxx_charge.attributes.next_update) | timestamp_custom('%I:%M %p') %}
{{ day }} {{ date }}{{ suffix(date) }} {{ time }}
- platform: template
sensors:
leaf_last_attempt:
friendly_name: 'Leaf Previous Attempt'
value_template: >
{%- macro suffix(d) %}
{%- set sfx = {1:'st',2:'nd',3:'rd'} %}
{{- 'th' if 11 <= d <= 13 else sfx.get(d%10, 'th') }}
{%- endmacro %}
{% set day = as_timestamp(states.sensor.xxxxxxx_charge.attributes.last_attempt) | timestamp_custom('%a') %}
{% set date = as_timestamp(states.sensor.xxxxxxx_charge.attributes.last_attempt) | timestamp_custom('%d') |int %}
{% set time = as_timestamp(states.sensor.xxxxxxx_charge.attributes.last_attempt) | timestamp_custom('%I:%M %p') %}
{{ day }} {{ date }}{{ suffix(date) }} {{ time }}
- platform: template
sensors:
leaf_last_update:
friendly_name: 'Leaf Last Update'
value_template: >
{%- macro suffix(d) %}
{%- set sfx = {1:'st',2:'nd',3:'rd'} %}
{{- 'th' if 11 <= d <= 13 else sfx.get(d%10, 'th') }}
{%- endmacro %}
{% set day = as_timestamp(states.sensor.xxxxxxx_charge.attributes.updated_on) | timestamp_custom('%a') %}
{% set date = as_timestamp(states.sensor.xxxxxxx_charge.attributes.updated_on) | timestamp_custom('%d') |int %}
{% set time = as_timestamp(states.sensor.xxxxxxx_charge.attributes.updated_on) | timestamp_custom('%I:%M %p') %}
{{ day }} {{ date }}{{ suffix(date) }} {{ time }}
- platform: template
sensors:
leaf_updating:
friendly_name: 'Leaf Update Status'
value_template: "{{ states.sensor.xxxxxxx_charge.attributes.update_in_progress }}"
@filcole the component doesn’t seem to gracefully handle a failed initial login, albeit that’s quite hard to simulate (maybe modify pycarwings to return the below when testing it?
{"status":"-2001","message":"INVALID PARAMS"}'
That seems to be a popular one with the Nissan servers. I’ve just been updating to 0.9 today and it was working fine until the last restart of HASS (of course…) which is how I know there aren’t any invalid params here. Obviously trying to spam their servers with login requests is a bad idea but maybe retrying every half hour or so?
What doesn’t help is that password reset malarky made an absolute mess of authentication as they mucked up synchronising passwords between CarWings and YouPlus Nissan. I’m waiting for the day CarWings just stops working altogether really.
Just a word of thanks for all the work put in.
I looked at getting something in to HA for my leaf in early 2017 but a young baby and a new house put paid to that.
I really appreciate the opportunities this offers for automation.
Cheers.