Skip to content

ZeroDivisionError #1098

@Destroyer061090

Description

@Destroyer061090

Describe the bug
The addon seems working but sensor in homeassistant is not anymore working without changing nothing

Config file

rest:
  - resource: "http://MYIP:MYPORT/get_vehicleinfo/MYVIN"
    scan_interval: 300
    sensor:
      - name: PSA
        unique_id: psa
        value_template: "OK"
        json_attributes:
          - energy
          - timed_odometer
          - battery
          - last_position
          - preconditionning
          - kinetic

  - resource: "http://MYIP:MYPORT/charge_control?vin=MYVIN&always_check=true"
    scan_interval: 300
    sensor:
      - name: "PSA Charge Control"
        unique_id: psa_charge_control
        value_template: "OK"
        json_attributes:
          - _next_stop_hour
          - percentage_threshold

rest_command:
  psa_wakeup:
    url: "http://MYIP:MYPORT/wakeup/MYVIN"
  psa_climate_on:
    url: "http://MYIP:MYPORT/preconditioning/MYVIN/1"
  psa_climate_off:
    url: "http://MYIP:MYPORT/preconditioning/MYVIN/0"
  psa_change_charge_threshold:
    url: "http://MYIP:MYPORT/charge_control?vin=MYVIN&percentage={{ states('input_number.psa_charging_threshold') | int }}"
    method: GET

template:
  - sensor:
      - name: PSA Status
        unique_id: psa_status
        state: >-
          {% if state_attr('sensor.psa', 'energy') is not none %}
            WORKING
          {% else %}
            NOT WORKING
          {% endif %}

      - name: PSA Charging Status
        unique_id: psa_charging_status
        state: >-
          {% if state_attr('sensor.psa', 'energy') is not none %}
            {{state_attr('sensor.psa', 'energy')[0]["charging"]["status"]}}
          {% else %}
            0
          {% endif %}

      - name: PSA Fuel Level
        unique_id: psa_fuel_level
        state: >-
          {% if state_attr('sensor.psa', 'energy') is not none %}
            {{ state_attr('sensor.psa', 'energy')[1].level }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: "%"
        #device_class: battery

      - name: PSA Autonomy Fuel
        unique_id: psa_autonomy_fuel
        state: >-
          {% if state_attr('sensor.psa', 'energy') is not none %}
            {{ state_attr('sensor.psa', 'energy')[1]["autonomy"] | round(0, "floor") }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: "km"
        icon: "mdi:map-marker-distance"
        device_class: distance
        state_class: measurement

      - name: PSA Battery Level
        unique_id: psa_battery_level
        state: >-
          {% if state_attr('sensor.psa', 'energy') is not none %}
            {{ state_attr('sensor.psa', 'energy')[0].level }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: "%"
        device_class: battery

      - name: PSA Mileage
        unique_id: psa_mileage
        state: >-
          {% if state_attr('sensor.psa', 'timed_odometer') is not none %}
            {{ state_attr('sensor.psa', 'timed_odometer')["mileage"] | round(0, "floor") }}
          {% else %}
            
          {% endif %}
        unit_of_measurement: "km"
        icon: "mdi:road-variant"
        device_class: distance
        state_class: total_increasing

      - name: PSA Range
        unique_id: psa_range
        state: >-
          {% if state_attr('sensor.psa', 'energy') is not none %}
            {{ state_attr('sensor.psa', 'energy')[0]["autonomy"] | round(0, "floor") }}
          {% else %}
            None
          {% endif %}
        unit_of_measurement: "km"
        icon: "mdi:map-marker-distance"
        device_class: distance
        state_class: measurement

      - name: PSA Preconditioning Status
        unique_id: psa_preconditioning_status
        state: >-
          {% if state_attr('sensor.psa', 'preconditionning') is not none %}
            {{ state_attr('sensor.psa', 'preconditionning').air_conditioning.status }}
          {% else %}
            Disabled
          {% endif %}

      - name: PSA Charging Mode
        unique_id: psa_charging_mode
        state: >-
          {% if state_attr('sensor.psa', 'energy') is not none %}
            {{ state_attr('sensor.psa', 'energy')[0].charging.charging_mode }}
          {% else %}
            Slow
          {% endif %}
        icon: mdi:lightning-bolt

      - name: PSA Charge Rate
        unique_id: psa_charge_rate
        state: >-
          {% if state_attr('sensor.psa', 'energy') is not none %}
            {{ state_attr('sensor.psa', 'energy')[0].charging.charging_rate }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: "mph"
        icon: mdi:speedometer
        device_class: speed
        state_class: measurement

      - name: PSA Charging Plugged
        unique_id: psa_charging_plugged
        state: >-
          {% if state_attr('sensor.psa', 'energy') is not none %}
            {{ state_attr('sensor.psa', 'energy')[0]["charging"]["plugged"] | round(0, "floor") }}
          {% else %}
            Unknown
          {% endif %}

      - name: "PSA Next Stop Time"
        unique_id: psa_next_stop_hour
        state: >-
          {{ state_attr('sensor.psa_charge_control','_next_stop_hour') }}

      - name: "PSA Charge Threshold"
        unique_id: psa_charge_threshold
        state: >-
          {% if state_attr('sensor.psa', 'energy') is not none %}
            {{ state_attr('sensor.psa_charge_control','percentage_threshold') | default(80) | int }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: "%"
        state_class: measurement

  - binary_sensor:
      - name: PSA Plugged In
        unique_id: psa_plugged_in
        state: >-
          {% if state_attr('sensor.psa', 'energy') is not none %}
            {{ state_attr('sensor.psa', 'energy')[0].charging.plugged }}
          {% else %}
            unknown
          {% endif %}
        device_class: connectivity

      - name: PSA Position
        unique_id: psa_position
        state: >-
          {% if state_attr('sensor.psa', 'kinetic') is not none %}
            {{ state_attr('sensor.psa', 'kinetic').moving }}
          {% else %}
            unknown
          {% endif %}
        device_class: moving
        attributes:
          latitude: >-
            {% if state_attr('sensor.psa', 'last_position') is not none %}
              {{ state_attr('sensor.psa', 'last_position').geometry.coordinates[1] }}
            {% else %}
              0
            {% endif %}
          longitude: >-
            {% if state_attr('sensor.psa', 'last_position') is not none %}
              {{ state_attr('sensor.psa', 'last_position').geometry.coordinates[0] }}
            {% else %}
              0
            {% endif %}

Environment (please complete the following information):

  • OS: addon installed on docker
  • Brand and model of car: Pegeout 508

Logs

logs.txt

I have also saw this:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions