Daily random pokemon

Playing around like this. I am going to try and make a card that “looks” like a card. YOu can get alot of the verbage if you can to some of those links. Fun project.

I implemented a “pokeball” button in this, clicking it will grab a new one. Although the images sometimes lag or do not exist, I will need to examine that.

type: custom:stack-in-card
mode: vertical
cards:
  - type: custom:mushroom-template-card
    entity: sensor.random_pokemon
    primary: Grab a Pokemon!
    secondary: Hold to Grab different Pokemon
    icon: mdi:pokeball
    icon_color: red
    tap_action:
      action: none
    hold_action:
      action: call-service
      service: homeassistant.update_entity
      data: {}
      target:
        entity_id: sensor.random_pokemon
  - type: custom:mushroom-title-card
    entity: sensor.random_pokemon
    title: '{{state_attr(''sensor.random_pokemon'',''name'') | capitalize}}'
    secondary: ''
    icon_type: none
    tap_action:
      action: none
  - type: custom:config-template-card
    entities:
      - sensor.random_pokemon
    card:
      type: picture
      image: >-
        ${'https://unpkg.com/[email protected]/sprites/pokemon/other/dream-world/'
        + states['sensor.random_pokemon'].attributes.id + '.svg'}

This uses stack-in and mushroom cards though, so be sure if you copy this that you have these installed. Otherwise you can just use built-in Button and Markdown and Vertical stacking or Grid.

Actually changing the picture card to picture-entity card seems much better as it auto updates the card when the entity updates:

    card:
      type: picture-entity
      entity: sensor.random_pokemon
      show_name: false
      show_state: false
      image: >-
        ${'https://unpkg.com/[email protected]/sprites/pokemon/other/dream-world/'
        + states['sensor.random_pokemon'].attributes.id + '.svg'}

1 Like

Is this installed through HACS?

If not, you would get an error.
I would also note that I found a few times I did not get an image, possibly that second URL does not have SVG images for all Pokemon (or the ones 1 through 1000 which is what I have in the random sensor),

Yeah, I have all those installed and I can get everything except the photo. My husband says that it may have something to do with /dream-world/ being part of the url since not all Pokémon are in there, but there’s got to be a list of photos somewhere?

I would say he is correct, I have seen a few missing. You can run update entity to update that sensor and get another one loaded and see.

You should maybe also just go to here in a browser:

https://unpkg.com/[email protected]/sprites/pokemon/other/dream-world/615.svg

Do you get an image?

Possibly I can change for this:

https://veekun.com/dex/media/pokemon/dream-world/

You can see them all there. Given that, likely only 1 - 649 would work. I have no idea so I leave that to the poke-experts to correct me!

Thanks, this is what I was after.
FYI the range should be 1 - 1008 (number of pokemon currently)

Beware that the grabbing of super-nice, large SVG sprites (versus the small images in through pokeapi) I would only find 1 - 649. You can also shorten the update by downloading the whole collection local from here:

If someone knows a source for all 1008 in HQ SVG format, that would be great to know.

I can confirm the best thing is to download the images locally and remove the call. It now is super fast. However, you only have id’s #1 - #649 in the set I found so anything above #650 displays no image.

Update:

After reviewing the data of several pokemon, I think I understand the image pattern.
This repository: GitHub - PokeAPI/sprites: Repository containing all the Pokémon sprites
Actually has all of the images, it can be determined using this:

            "official-artwork": {
                "front_default": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/84.png",
                "front_shiny": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/shiny/84.png"
            }

So ll the images could be switched over to PNG versions and not the SVG versions from Dream World as this does not have all the images.

OK. Based on some “poking” around the data. It looks like all the images could be just grabbed from the actual data. The sensor attribute is “sprites” and the path below is other.official-artwork.front_default as in:

 "sprites": {
        "back_default": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/84.png",
        "back_female": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/female/84.png",
        "back_shiny": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/shiny/84.png",
        "back_shiny_female": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/shiny/female/84.png",
        "front_default": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/84.png",
        "front_female": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/female/84.png",
        "front_shiny": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/shiny/84.png",
        "front_shiny_female": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/shiny/female/84.png",
        "other": {
            "dream_world": {
                "front_default": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/dream-world/84.svg",
                "front_female": null
            },
            "home": {
                "front_default": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/home/84.png",
                "front_female": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/home/female/84.png",
                "front_shiny": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/home/shiny/84.png",
                "front_shiny_female": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/home/shiny/female/84.png"
            },
            "official-artwork": {
                "front_default": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/84.png",
                "front_shiny": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/shiny/84.png"
            }
        },

So one could just use that path to get a full-size PNG.

Personally I downloaded them and will load them from local disk. I have huge disk space on my HA setup. Example of the PNGs

Images 1 through 1008 (without shiny ones) is 124MB

As you can see, all now from 1 to 1008 should have images if you use those links. Here’s Wyrdeer #899

Give me a few weeks and I think I can build most all of this if this is something people want:

I am grabbing the name, height, weight, number, image, one sprite now … getting the other data is not that bad.

2 Likes

I’d love to see what you come up with! How did you get the image to not have the border around it btw?

Heres what I have so far:

type: custom:stack-in-card
mode: vertical
keep:
  background: true
  box_shadow: false
  margin: false
  outer_padding: true
  border_radius: false
cards:
  - type: custom:mushroom-template-card
    entity: sensor.random_pokemon
    primary: Grab a Pokemon!
    secondary: Hold to Grab different Pokemon
    icon: mdi:pokeball
    icon_color: red
    tap_action:
      action: none
    hold_action:
      action: call-service
      service: homeassistant.update_entity
      data: {}
      target:
        entity_id: sensor.random_pokemon
    card_mod:
      style: |
        ha-card {
         border: none;
        }
  - type: custom:mushroom-chips-card
    chips:
      - type: template
        entity: sensor.random_pokemon
        content: 'ID: {{state_attr(''sensor.random_pokemon'', ''id'') }}'
      - type: template
        entity: sensor.random_pokemon
        content: 'Weight: {{state_attr(''sensor.random_pokemon'', ''weight'') }}'
      - type: template
        entity: sensor.random_pokemon
        content: 'Height: {{state_attr(''sensor.random_pokemon'', ''height'') }}'
    alignment: justify
    card_mod:
      style: |
        ha-card {
        --chip-box-shadow: none;
        --chip-background: none;
        --background: none;
        --chip-border-width: 0;
          }
  - type: custom:mushroom-title-card
    entity: sensor.random_pokemon
    title: >-
      {{state_attr('sensor.random_pokemon','name') | capitalize}}: #{{
      state_attr("sensor.random_pokemon", "id") }}
    subtitle: |-
      type: {% for tp in state_attr("sensor.random_pokemon","types") -%}
      {{ tp.type.name }}
      {% endfor %}
    icon_type: none
    tap_action:
      action: none
  - type: custom:config-template-card
    entities:
      - sensor.random_pokemon
    card:
      type: picture-entity
      entity: sensor.random_pokemon
      show_name: false
      show_state: false
      image: >-
        ${'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/'
        + states['sensor.random_pokemon'].attributes.id + '.png'}
      card_mod:
        style: |
          ha-card: {
           border: none;
           }
card_mod:
  style: |
    ha-card: {
    border: none;
    background: none;
    box-shadow: 0px;
    }

My husband was super excited about this card! He asked if I would be able to include the game/generation where the pokemon was first introduced as well so that is what I am working on now.

Looking really fun! Not sure about that border. I do not have that “keep” section in stack-in looks to be the only difference.

By the way, I changed the stats part to report them like units …

subtitle: >
      National No: {{state_attr('sensor.random_pokemon','id') }}, Height:
      {{state_attr('sensor.random_pokemon','height')/10}} m, Weight:
      {{state_attr('sensor.random_pokemon','weight')/10 }} kg

So I get meters and kilograms now.

As for gave/generation … I am not a Pokemon person, I just thought the project sounded fun and thought I could help everyone get to the data. I am sure it is either there or in alternate links that are in the main one.

1 Like

Love it! That seems easier than having them as chips. I was just trying to think of what a pokemon card looked like from memory (apparently I forgot I could just google it!)

By the way, I downloaded all those PNGs and I store them locally. I do this for many things but to be honest I have a super-slow internet as I live in the middle of nowhere. So I do this:

    card:
      type: picture-entity
      entity: sensor.random_pokemon
      show_name: false
      show_state: false
      image: >-
        ${'http://192.168.2.245:8123/local/Pokemon/Sprites/Master/' +
        states['sensor.random_pokemon'].attributes.id + '.png'}

And since the entire collection of PNGs is on my HA server, it is super fast for the image. If I run my “Grab a Pokemon”, I have everything in about 0.5 seconds

I really apprecaite all the help you’ve given me so far! Thank you very much :smiley:

Home about a Mushroom inut select with every Pokemon? Like this:

1 Like

This is awesome, really excited people are getting into my silly idea!

I’m playing around also, what data I am aiming for is:
name, height, weight number, image or default front sprite, type, and maybe moves

The whole idea for me was to have it change daily and hope my daughter finds it interesting / exciting to see whats going to be tomorrow.

I have changed it up a little, removed the scan interval and then made a simple automation that refreshes the sensor at sunrise.

EDIT: Turns out removing the scan interval breaks it so I am extending it to 2 days so the automation is what triggers it.

I would also like to do this for the types, abilities and maybe moves, but I am struggling to get the example you provided working in the attributes of the sensor, are you able to elaborate a little?

Well, you do not use that in the attributes of a sensor (unless you actually want to create a new sensor). Since that information is already in the master sensor, you can get it into “something”.

Now that “something” depends on how you want it to display in the GUI. Let’s say you wanted that information in a simple Markdown Card. You could do this:

type: markdown
content: |-
  ## Types
  {% for tp in state_attr("sensor.random_pokemon","types") -%}
    {{ tp.type.name }}
  {% endfor %}
  ## Abilities
  {% for ab in state_attr("sensor.random_pokemon","abilities") -%}
    {{ ab.ability.name }}
  {% endfor %}
  ## Moves
  {% for mv in state_attr("sensor.random_pokemon","moves") -%}
    {{ mv.move.name }}
  {% endfor %}

Which would give you this:

To everyone following this, I noticed an error in the original sensor. I had typed “states” as one of the attributes. It is “stats” and should be like this:

  json_attributes:
    - abilities
    - base_experience
    - forms
    - game_indicies
    - height
    - held_items
    - id
    - is_default
    - location_area_encounters
    - moves
    - name
    - order
    - past_types
    - species
    - sprites
    - stats
    - types
    - weight

I noticed this in trying to get the Stats like HP, Attack, etc. Change that sensor to use “stats” and now I get the info:

1 Like

Good catch!
How did you get the stat name and base_stat in the same line? I am getting an error message with endfor

Right now, that card is this (note that it is st.stat.name but it is only st.base_stat ):

type: markdown
content: |-
  ## Types
  {% for tp in state_attr("sensor.random_pokemon","types") -%}
    {{ tp.type.name }}
  {% endfor %}
  ## Abilities
  {% for ab in state_attr("sensor.random_pokemon","abilities") -%}
    {{ ab.ability.name }}
  {% endfor %}
  ## Stats
  {% for st in state_attr("sensor.random_pokemon","stats") -%}
    {{ st.stat.name }} {{ st.base_stat }}
  {% endfor %}
  ## Moves
  {% for mv in state_attr("sensor.random_pokemon","moves") -%}
    {{ mv.move.name }}
  {% endfor %}

BUT. I just posted to the Apex chart gurus because I want to move the stats into a small chart, like is done on Pokedex. Ideally I would like something like this:

Playing around, I am getting closer!

1 Like