Custom sensor returning state of >1 default sensor?

Hi all –

Stumbling my way through Home Assistant. :slight_smile:

I am trying to make a custom sensor that will display a charging icon if my phone is charging and if it is not charging display the icon of phone_battery_level. I’ve got this so far:

  - sensor:
      - name: "Phone Battery Custom"
        state: >
          {% if is_state('binary_sensor.phone_is_charging', 'on') %}
          {% endif %}

I know I can add {% else %} and add more conditions, but how do I return the state of binary_sensor.phone_battery_level? Much like I have charging if charging is detected?

Am I going about this the wrong way?

Yes :slight_smile: Forget the sensor and use this custom Lovelace card instead:

It does all the hard work for you.

Screenshot 2022-01-14 at 13-17-47 Administration - Home Assistant

  - entity: sensor.iphonex_battery_level
    tap_action: more-info
    secondary_info: charging
      entity_id: sensor.iphonex_battery_state
      state: Charging
    type: custom:battery-state-entity
  - entity: sensor.ipad_pro_battery_level
    tap_action: more-info
    secondary_info: charging
      entity_id: sensor.ipad_pro_battery_state
      state: Charging
    type: custom:battery-state-entity
show_header_toggle: false
title: Battery Sensors
type: entities

Been playing with that. Is there a way to drop the title, state, etc. I just want the icon and the %.