Display ISP name from IP address

I use the following code extract on a dashboard, but instead of the IP states('sensor.myip) I would like to show the ISP name e.g. any IP prefixed with 145 (145.x.x.x) should show “Starlink” and anything else is ISP B? I have tried various ways, but can’t figure it out? I thought it should be as simple as manipulating a string?

type: custom:vertical-stack-in-card
mode: horizontal
square: false
columns: 1
cards:
  - type: custom:mushroom-template-card
    primary: Internet ({{states('sensor.myip') }})
    icon: mdi:web
    icon_color: blue
    layout: horizontal
    secondary: >-
      {{states('sensor.speedtest_download') }} Mbit/s |
      {{states('sensor.speedtest_upload') }} Mbit/s |
      {{states('sensor.speedtest_ping') }} ms |
      {{relative_time(states.sensor.speedtest_download.last_updated) }} ago
  - square: false
    

Dashboard

Think this might work, template works but not sure how the mushroom card works

type: custom:vertical-stack-in-card
mode: horizontal
square: false
columns: 1
cards:
  - type: custom:mushroom-template-card
    primary: Internet ({% if states('sensor.myip').startswith("145") %} Starlink {% else %} ISP B {% endif %}
)
    icon: mdi:web
    icon_color: blue
    layout: horizontal
    secondary: >-
      {{states('sensor.speedtest_download') }} Mbit/s |
      {{states('sensor.speedtest_upload') }} Mbit/s |
      {{states('sensor.speedtest_ping') }} ms |
      {{relative_time(states.sensor.speedtest_download.last_updated) }} ago
  - square: false
1 Like

Thank you, works perfectly - another one to file carefully away :slight_smile: Always learning…

This is a really cool idea! Mind sharing your full code with the graphs as well?
Also, how did you discover that the prefix is associated with a specific ISP?

Sure, the ISP IP address will show in your router.

type: custom:vertical-stack-in-card
mode: horizontal
square: false
columns: 1
cards:
  - type: custom:mushroom-template-card
    primary: >-
      Internet ({% if states('sensor.myip').startswith("145") %}Starlink) {%
      else %} Boundless) {% endif %}
    icon: mdi:web
    icon_color: blue
    layout: horizontal
    secondary: >-
      {{states('sensor.speedtest_download') }} Mbit/s |
      {{states('sensor.speedtest_upload') }} Mbit/s |
      {{states('sensor.speedtest_ping') }} ms |
      {{relative_time(states.sensor.speedtest_download.last_updated) }} ago
  - square: false
    columns: 1
    type: grid
    cards:
      - type: custom:vertical-stack-in-card
        horizontal: true
        cards:
          - type: custom:mushroom-template-card
            secondary: Starlink
            entity: switch.starlink
            layout: vertical
            tap_action:
              action: toggle
            icon: |-
              {% if is_state('switch.starlink', 'on') %}
                mdi:power-plug
              {% else %}
                mdi:power-plug-outline
              {% endif %}
            icon_color: |-
              {% if is_state('switch.starlink', 'on') %}
                green
              {% else %}
                red
              {% endif %}
          - type: custom:mini-graph-card
            entities:
              - sensor.speedtest_download
            name: Download
            line_color: blue
            line_width: 8
            font_size: 75
          - type: custom:mini-graph-card
            entities:
              - sensor.speedtest_upload
            name: Upload
            show:
              icon: true
              label: false
              state: true
            hours_to_show: 24
            line_color: '#e74c3c'
            line_width: 8
            font_size: 75

Thanks for the quick reply! So the graph part is the second “square: false” and the 2 lines under it?
When I tried that code, I got an error for invalid configuration

Ive just updated the post - full code now posted…

1 Like

Thank you!

If you wanted to extend this further, you could pass your sensor.myip into an api such as API Documentation - ipapi to be able to lookup the registered ISP against your IP.