Which part? Do you mean the selector to select a specific pokemon?
Step 1: Create a basically empty list. You need at least one option but it will be overwritten.
#############################
######### pokedex ###########
#############################
pokedex:
options:
- Bulbasaur
Step 2: I found the API call to get the complete list of Pokemon. SO I have a senosr that gets this information:
- platform: rest
name: Pokedex
scan_interval: 360000
resource_template: https://pokeapi.co/api/v2/pokemon/?limit=1008
value_template: "{{ now() }}"
json_attributes:
- results
Step 3: On Home Assistant Start, put them all into a list via an automation:
- id: '1675715210686'
alias: Build Pokedex Options
description: ''
trigger:
- platform: homeassistant
event: start
condition: []
action:
- service: input_select.set_options
data_template:
entity_id: input_select.pokedex
options: "{% set pdex = namespace(poke=[]) %}\n {% for pokemon in state_attr('sensor.pokedex','results')
\ %} \n {% set pdex.poke = pdex.poke + [pokemon.name] %}\n {% endfor %}\n{{
pdex.poke | list }}"
mode: single
You now have input_select.pokedex
that is allows you to select a particular Pokemon as opposed to a random one.
As it turns out, you can call the API to get a specific Pokemon in two ways. You can use the “id” which we already set up or “random”, but instead of an id, you can just use the name. SO I modified the sensor like this:
- platform: rest
name: Random Pokemon
scan_interval: 360000
resource_template: >
{% if states('input_select.select_pokemon_mode') == 'Increment' %}
https://pokeapi.co/api/v2/pokemon/{{ state_attr('sensor.random_pokemon','id') + 1 }}
{% elif states('input_select.select_pokemon_mode') == 'Decrement' %}
https://pokeapi.co/api/v2/pokemon/{{ state_attr('sensor.random_pokemon','id') - 1 }}
{% elif states('input_select.select_pokemon_mode') == 'Name' %}
https://pokeapi.co/api/v2/pokemon/{{ states('input_select.pokedex') }}
{% else %}
https://pokeapi.co/api/v2/pokemon/{{ range(1, 1008) | random }}
{% endif %}
value_template: "{{ now() }}"
It defaults to “random” but if you call it with a name, it will get the named Pokemon. This also has the Increment and Decrement too. IT uses a simple input_select that has only “Name”, “Increment”, “Decrement” and “Random” as options which you can use to create all four ways across the top.
And I tie it all together with this script:
get_pokemon:
alias: Get Pokemon
variables:
pokemode: Increment
sequence:
- service: input_select.select_option
data:
option: '{{ pokemode }}'
target:
entity_id: input_select.select_pokemon_mode
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.random_pokemon
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.pokemon_species
- service: input_select.select_option
data:
option: Random
target:
entity_id: input_select.select_pokemon_mode
- service: input_select.select_option
data:
option: '{{state_attr(''sensor.random_pokemon'',''name'') }}'
target:
entity_id: input_select.pokedex
mode: single
So clicking any one of the button on the top will set the input select “mode”, then update sensor.random_pokemon. IT also updates the other sensor I created that has Pokemon descriptions, then it sets it back to random. I likely could even get rid of the “mode” input_select, I only used it for testing and it is hidden now.
Example to call it:
- type: custom:mushroom-template-card
entity: sensor.random_pokemon
primary: Previous Pokemon
secondary: Show Previous Pokemon
icon: mdi:backburger
icon_color: red
tap_action:
action: none
hold_action:
action: call-service
service: script.get_pokemon
data:
pokemode: Decrement
target: {}
Ultimately you have this: