kia_uvo icon indicating copy to clipboard operation
kia_uvo copied to clipboard

Question: Sensor update after service calls

Open nprez83 opened this issue 2 years ago • 6 comments

First off thanks for the ongoing work on this great integration. I was wondering if there's a way to have the sensor state update automatically after a service call is ran, like it used to be before the switch to this API integration. As of now, when I run a service call (e.g., start climate, lock/unlock) I have to then call the update service to fetch the updated data. I may be wrong, but I thought the sensor data was updated automatically with the previous implementation.

nprez83 avatar Feb 07 '23 02:02 nprez83

Depending on the region you are most likely correct. The old one still had "last action tracking" we are working to implement that currently. What region are you using?

cdnninja avatar Feb 07 '23 03:02 cdnninja

I should clarify my above. Today we request an update right after the call, sometimes the API isn't done yet with the command. I can temporarily add a delay to that and it will help. The previous solution for some regions checked on the last call over and over until done and then placed the update call.

cdnninja avatar Feb 07 '23 04:02 cdnninja

Ahh, no worries. That's basically what I'm doing in my script right now, I send the command, wait 30 secs and check for the sensor status (engine, door, etc). I do that in a loop 6 times (so for 3 mins) and if the service call doesn't succeed I send a notification. I think that's totally fine, was just wondering if there was something easy on your end, but I think it's best to leave it as is and have the user manually call the update service on their own accord. Thanks as always.

nprez83 avatar Feb 07 '23 16:02 nprez83

@nprez83 Could you provide an example of that script? Would be interested in creating a similar automation. Right now I am just force updating no matter if the value is changed or not.

rindlerblabla avatar Feb 07 '23 22:02 rindlerblabla

Sure thing, sorry for delay. See below the scripts I use for starting and locking my Telluride. The input helpers I refer to in the script correspond to buttons on a picture-elements card, which I also use to activate the scripts. I'm including the yaml for that as well in case any one would like to use it. I have similar scripts for stopping the engine and unlocking the doors (which you'll see referred in the card) that are fairly similar to the ones below, so I'm not including. Enjoy! FYI, the theme I use is noctis in case you're wondering.

alias: Kia - Climate start
sequence:
  - service: kia_uvo.start_climate
    data:
      device_id: YOUR_DEVICE_ID
      duration: 10
      climate: "{{ iif(is_state('input_boolean.telluride_ac_on','on')) }}"
      temperature: "{{ states('input_number.telluride_temp_set') | int }}"
      defrost: "{{ iif(is_state('input_boolean.telluride_defroster_on','on')) }}"
      heating: "{{ iif(is_state('input_boolean.telluride_accessories_on','on'),'1') }}"
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.telluride_engine_starting_stopping
  - wait_for_trigger:
      - type: turned_on
        platform: device
        device_id: YOUR_DEVICE_ID
        entity_id: binary_sensor.telluride_engine
        domain: binary_sensor
    timeout:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - repeat:
      until:
        - condition: or
          conditions:
            - type: is_on
              condition: device
              device_id: YOUR_DEVICE_ID
              entity_id: binary_sensor.telluride_engine
              domain: binary_sensor
            - condition: template
              value_template: "{{ repeat.index == 6 }}"
      sequence:
        - service: kia_uvo.update
          data:
            device_id: YOUR_DEVICE_ID
        - wait_for_trigger:
            - type: turned_on
              platform: device
              device_id: YOUR_DEVICE_ID
              entity_id: binary_sensor.telluride_engine
              domain: binary_sensor
          timeout:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0
    enabled: true
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.telluride_engine_starting_stopping
  - choose:
      - conditions:
          - type: is_off
            condition: device
            device_id: YOUR_DEVICE_ID
            entity_id: binary_sensor.telluride_engine
            domain: binary_sensor
        sequence:
          - service: notify.phones
            data:
              message: >-
                Something went wrong when trying to start the Telluride, please
                try again.
              data:
                ttl: 0
                priority: high
                notification_icon: mdi:car-info
    default:
      - service: notify.phones
        data:
          message: Telluride climate has been started by Home Assistant.
          data:
            ttl: 0
            priority: high
            notification_icon: mdi:engine
            tag: kia_started
      - delay:
          hours: 0
          minutes: 0
          seconds: 30
          milliseconds: 0
      - service: notify.phones
        data:
          message: clear_notification
          data:
            ttl: 0
            priority: high
            tag: kia_started
mode: single
icon: mdi:air-conditioner
alias: Kia - Doors lock
sequence:
  - service: kia_uvo.lock
    data:
      device_id: YOUR_DEVICE_ID
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.telluride_locking_unlocking
  - wait_for_trigger:
      - platform: device
        device_id: YOUR_DEVICE_ID
        domain: lock
        entity_id: lock.telluride_door_lock
        type: locked
    timeout:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - repeat:
      until:
        - condition: or
          conditions:
            - condition: device
              device_id: YOUR_DEVICE_ID
              domain: lock
              entity_id: lock.telluride_door_lock
              type: is_locked
            - condition: template
              value_template: "{{ repeat.index == 6 }}"
      sequence:
        - service: kia_uvo.update
          data:
            device_id: YOUR_DEVICE_ID
        - wait_for_trigger:
            - platform: device
              device_id: YOUR_DEVICE_ID
              domain: lock
              entity_id: lock.telluride_door_lock
              type: locked
          timeout:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0
    enabled: true
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.telluride_locking_unlocking
  - choose:
      - conditions:
          - condition: device
            device_id: YOUR_DEVICE_ID
            domain: lock
            entity_id: lock.telluride_door_lock
            type: is_unlocked
        sequence:
          - service: notify.phones
            data:
              message: >-
                Something went wrong when trying to lock the Telluride doors,
                please try again.
              data:
                ttl: 0
                priority: high
                notification_icon: mdi:car-info
    default:
      - service: notify.phones
        data:
          message: Telluride doors have been locked by Home Assistant.
          data:
            ttl: 0
            priority: high
            notification_icon: mdi:car-door-lock
            tag: kia_doors_locked
      - delay:
          hours: 0
          minutes: 0
          seconds: 30
          milliseconds: 0
      - service: notify.phones
        data:
          message: clear_notification
          data:
            ttl: 0
            priority: high
            tag: kia_doors_locked
mode: single
icon: mdi:car-door-lock
type: custom:swipe-card
parameters:
  scrollbar: null
cards:
  - type: picture-elements
    image: /local/custom/2020-Kia-Telluride-Gravity-Gray.png
    elements:
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_front_left_door
            state: 'on'
        elements:
          - type: image
            image: /local/custom/custom_door_open_FL_red.png
            style:
              left: 22px
              top: 65px
              width: 6%
            tap_action:
              action: none
            state_color: true
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_front_right_door
            state: 'on'
        elements:
          - type: image
            image: /local/custom/custom_door_open_FR_red.png
            style:
              left: 22px
              top: 65px
              width: 6%
            tap_action:
              action: none
            state_color: true
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_back_left_door
            state: 'on'
        elements:
          - type: image
            image: /local/custom/custom_door_open_RL_red.png
            style:
              left: 22px
              top: 65px
              width: 6%
            tap_action:
              action: none
            state_color: true
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_back_right_door
            state: 'on'
        elements:
          - type: image
            image: /local/custom/custom_door_open_RR_red.png
            style:
              left: 22px
              top: 65px
              width: 6%
            tap_action:
              action: none
            state_color: true
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_trunk
            state: 'on'
        elements:
          - type: image
            image: /local/custom/custom_trunk_open_red.png
            style:
              left: 65px
              top: 60px
              width: 9%
            tap_action:
              action: none
            state_color: true
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_hood
            state: 'on'
        elements:
          - type: image
            image: /local/custom/custom_hood_open_red.png
            style:
              left: 65px
              top: 60px
              width: 9%
            tap_action:
              action: none
            state_color: true
      - type: conditional
        conditions:
          - entity: input_boolean.telluride_engine_starting_stopping
            state: 'on'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_engine
            state_color: true
            icon: mdi:car-clock
            style:
              right: '-20px'
              top: 17px
              '--paper-item-icon-color': var(--green-color)
      - type: conditional
        conditions:
          - entity: input_boolean.telluride_engine_starting_stopping
            state: 'off'
          - entity: binary_sensor.telluride_engine
            state: 'off'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_engine
            state_color: true
            style:
              right: '-20px'
              top: 17px
            hold_action:
              action: call-service
              service: script.kia_climate_start
      - type: conditional
        conditions:
          - entity: input_boolean.telluride_engine_starting_stopping
            state: 'off'
          - entity: binary_sensor.telluride_engine
            state: 'on'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_engine
            state_color: true
            style:
              right: '-20px'
              top: 17px
            hold_action:
              action: call-service
              service: script.kia_climate_stop
              confirmation:
                text: Are you sure you want to turn the engine off?
      - type: conditional
        conditions:
          - entity: input_boolean.telluride_locking_unlocking
            state: 'off'
          - entity: lock.telluride_door_lock
            state: unlocked
        elements:
          - type: state-icon
            entity: lock.telluride_door_lock
            state_color: true
            style:
              right: '-22px'
              top: 60px
            hold_action:
              action: call-service
              service: script.kia_doors_lock
      - type: conditional
        conditions:
          - entity: input_boolean.telluride_locking_unlocking
            state: 'off'
          - entity: lock.telluride_door_lock
            state: locked
        elements:
          - type: state-icon
            entity: lock.telluride_door_lock
            state_color: true
            style:
              right: '-22px'
              top: 60px
            hold_action:
              action: call-service
              service: script.kia_doors_unlock
      - type: conditional
        conditions:
          - entity: input_boolean.telluride_locking_unlocking
            state: 'on'
        elements:
          - type: state-icon
            entity: lock.telluride_door_lock
            state_color: true
            icon: mdi:lock-clock
            style:
              right: '-22px'
              top: 60px
              '--paper-item-icon-color': var(--green-color)
      - type: state-icon
        icon: mdi:map-marker-radius
        entity: sensor.telluride_geocoded_location
        style:
          left: 15px
          top: 15px
      - type: state-label
        entity: device_tracker.telluride_location
        style:
          left: 49px
          top: 15px
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_engine
            state: 'on'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_air_conditioner
            style:
              left: 27%
              top: 17px
            state_color: true
          - type: state-label
            entity: sensor.telluride_set_temperature
            style:
              left: 27%
              top: 45px
              color: '#FFC300'
              font-weight: bold
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_engine
            state: 'off'
          - entity: input_boolean.telluride_ac_on
            state: 'off'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_air_conditioner
            style:
              left: 27%
              top: 17px
            state_color: true
            tap_action:
              action: call-service
              service: input_boolean.toggle
              service_data:
                entity_id: input_boolean.telluride_ac_on
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_engine
            state: 'off'
          - entity: input_boolean.telluride_ac_on
            state: 'on'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_air_conditioner
            style:
              left: 27%
              top: 17px
              '--paper-item-icon-color': var(--green-color)
            state_color: false
            tap_action:
              action: call-service
              service: input_boolean.toggle
              service_data:
                entity_id: input_boolean.telluride_ac_on
          - type: state-label
            entity: input_number.telluride_temp_set
            style:
              left: 27%
              top: 45px
              color: var(--green-color)
              font-weight: bold
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_engine
            state: 'on'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_defrost
            style:
              left: 45%
              top: 15px
            state_color: true
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_engine
            state: 'off'
          - entity: input_boolean.telluride_defroster_on
            state: 'off'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_defrost
            style:
              left: 45%
              top: 15px
            state_color: true
            tap_action:
              action: call-service
              service: input_boolean.toggle
              service_data:
                entity_id: input_boolean.telluride_defroster_on
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_engine
            state: 'off'
          - entity: input_boolean.telluride_defroster_on
            state: 'on'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_defrost
            style:
              left: 45%
              top: 15px
              '--paper-item-icon-color': var(--green-color)
            state_color: false
            tap_action:
              action: call-service
              service: input_boolean.toggle
              service_data:
                entity_id: input_boolean.telluride_defroster_on
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_engine
            state: 'on'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_steering_wheel_heater
            style:
              left: 62%
              top: 15px
            state_color: true
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_engine
            state: 'off'
          - entity: input_boolean.telluride_accessories_on
            state: 'off'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_steering_wheel_heater
            style:
              left: 62%
              top: 15px
            state_color: true
            tap_action:
              action: call-service
              service: input_boolean.toggle
              service_data:
                entity_id: input_boolean.telluride_accessories_on
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_engine
            state: 'off'
          - entity: input_boolean.telluride_accessories_on
            state: 'on'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_steering_wheel_heater
            style:
              left: 62%
              top: 15px
              '--paper-item-icon-color': var(--green-color)
            state_color: false
            tap_action:
              action: call-service
              service: input_boolean.toggle
              service_data:
                entity_id: input_boolean.telluride_accessories_on
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_engine
            state: 'on'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_back_window_heater
            style:
              left: 79%
              top: 15px
            state_color: true
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_engine
            state: 'off'
          - entity: input_boolean.telluride_accessories_on
            state: 'off'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_back_window_heater
            style:
              left: 79%
              top: 15px
            state_color: true
            tap_action:
              action: call-service
              service: input_boolean.toggle
              service_data:
                entity_id: input_boolean.telluride_accessories_on
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_engine
            state: 'off'
          - entity: input_boolean.telluride_accessories_on
            state: 'on'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_back_window_heater
            style:
              left: 79%
              top: 15px
              '--paper-item-icon-color': var(--green-color)
            state_color: false
            tap_action:
              action: call-service
              service: input_boolean.toggle
              service_data:
                entity_id: input_boolean.telluride_accessories_on
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_tire_pressure_all
            state: 'on'
        elements:
          - type: state-icon
            entity: binary_sensor.telluride_tire_pressure_all
            style:
              left: 17px
              bottom: 10px
              '--paper-item-icon-color': red
            state_color: false
      - type: state-icon
        entity: binary_sensor.telluride_fuel_low_level
        style:
          left: 18px
          bottom: '-18px'
        state_color: true
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_fuel_low_level
            state: 'off'
        elements:
          - type: state-label
            entity: sensor.telluride_fuel_driving_range
            style:
              left: 60px
              bottom: '-18px'
      - type: conditional
        conditions:
          - entity: binary_sensor.telluride_fuel_low_level
            state: 'on'
        elements:
          - type: state-label
            entity: sensor.telluride_fuel_driving_range
            style:
              color: orange
              left: 60px
              bottom: '-18px'
      - type: state-icon
        entity: sensor.telluride_car_battery_level
        style:
          left: 32%
          bottom: '-18px'
      - type: state-label
        entity: sensor.telluride_car_battery_level
        style:
          left: 41%
          bottom: '-18px'
      - type: state-icon
        entity: sensor.telluride_next_service
        style:
          right: 33%
          bottom: '-18px'
      - type: state-label
        entity: sensor.telluride_next_service
        style:
          right: 13%
          bottom: '-18px'
      - type: state-icon
        entity: sensor.telluride_last_updated_at
        state_color: false
        icon: mdi:refresh
        style:
          right: '-22px'
          bottom: '-18px'
          '--paper-item-icon-color': var(--green-color)
        tap_action:
          action: call-service
          service: kia_uvo.update
          data:
            device_id: YOUR_DEVICE_ID
      - type: state-icon
        entity: sensor.telluride_last_updated_at
        icon: mdi:refresh-circle
        style:
          right: 10px
          bottom: '-18px'
          '--paper-item-icon-color': orange
        tap_action:
          action: more-info
        hold_action:
          action: call-service
          service: kia_uvo.force_update
          data:
            device_id: YOUR_DEVICE_ID
  - type: markdown
    content: >-
      {% if 'house_number' in
      state_attr('sensor.telluride_geocoded_location','address') %} {% set
      house =
      state_attr('sensor.telluride_geocoded_location','address').house_number
      %} {% else %} {% set house = None %} {% endif %} {% if 'amenity' in
      state_attr('sensor.telluride_geocoded_location','address') %} {% set
      amenity =
      state_attr('sensor.telluride_geocoded_location','address').amenity
      %} {% else %} {% set amenity = None %} {% endif %} {% if 'building' in
      state_attr('sensor.telluride_geocoded_location','address') %} {% set
      building =
      state_attr('sensor.telluride_geocoded_location','address').building
      %} {% else %} {% set building = None %} {% endif %} {% if 'highway' in
      state_attr('sensor.telluride_geocoded_location','address') %} {% set
      highway =
      state_attr('sensor.telluride_geocoded_location','address').highway
      %} {% else %} {% set highway = None %} {% endif %} {% if 'neighbourhood'
      in state_attr('sensor.telluride_geocoded_location','address') %} {%
      set neighbourhood =
      state_attr('sensor.telluride_geocoded_location','address').neighbourhood
      %} {% else %} {% set neighbourhood = None %} {% endif %} {% if 'road' in
      state_attr('sensor.telluride_geocoded_location','address') %} {% set
      road =
      state_attr('sensor.telluride_geocoded_location','address').road %}
      {% else %} {% set road = None %} {% endif %} {% if 'city' in
      state_attr('sensor.telluride_geocoded_location','address') %} {% set
      city = state_attr('sensor.telluride_geocoded_location',
      'address').city %} {% else %} {% set city = None %} {% endif %} {% if
      'town' in state_attr('sensor.telluride_geocoded_location','address')
      %} {% set town =
      state_attr('sensor.telluride_geocoded_location','address').town %}
      {% else %} {% set town = None %} {% endif %} {% if 'state' in
      state_attr('sensor.telluride_geocoded_location', 'address') %}   {%
      set state =
      state_attr('sensor.telluride_geocoded_location','address').state %}
      {% else %} {% set state = None %} {% endif %} {% if 'postcode' in
      state_attr('sensor.telluride_geocoded_location','address') %} {% set
      postcode =
      state_attr('sensor.telluride_geocoded_location','address').postcode
      %} {% else %} {% set postcode = None %} {% endif %}

      {% if house != None and amenity != None %} {% set str_address = amenity ~
      '<br/>' ~ house ~ ' ' ~ road %} {% elif house != None %} {% set
      str_address = house ~ ' ' ~ road %} {% elif amenity != None %}   {% set
      str_address = amenity ~ '<br/>' ~ road ~ ', ' ~ neighbourhood %}  {% elif
      building != None %}  {% set str_address = building ~ '<br/>' ~ road ~ ', '
      ~ neighbourhood %} {% else %} {% set str_address = highway ~ '<br/>' ~
      road ~ ', ' ~ neighbourhood %} {% endif %}

      {% if city != None %} {% set city_town = city %}  {% else %} {% set
      city_town = town %} {% endif %}

      <ins>**Telluride Location:**</ins>


      {{ str_address }} <br/> {{ city_town }}, {{ state }} {{ postcode }}

image

nprez83 avatar Feb 12 '23 00:02 nprez83

Thanks a lot for the inspiration!

rindlerblabla avatar Feb 12 '23 12:02 rindlerblabla