Skip to content

Instantly share code, notes, and snippets.

@luixal
Last active March 21, 2025 22:05
Show Gist options
  • Save luixal/01a9effbbd71b4562db73f4cd8178b71 to your computer and use it in GitHub Desktop.
Save luixal/01a9effbbd71b4562db73f4cd8178b71 to your computer and use it in GitHub Desktop.
Home Assistant cards configuration

Mushroom Countdown with Input Hours

This card shows an hours input card while charger is off and a countdown when charger is running for the hours selected.

There's another version that adds a simple scheduling feature in top of this here.

Screeenshots

image

image

Dependencies

Cards needed:

  • Mushroom cards (mushroom-number-card)
  • Timer Bar Card

Other things needed:

  • Input number: input_number.ev_charge_timer_input
  • Timer helper: timer.ev_charge_timer

IMPORTANT: when creating the helpers, check the restore option or you'll be in trouble when restarting HA while this is working!

Automations

You need to create some automations to make this card work as expected. As my integrations have entity_ids and can't be used as is in other HAs, let's just explain them a little bit:

Start on input number change

When the input number is changed, the timer can be started using a template like this:

service: timer.start
data_template:
  duration: "{{ states.input_number.ev_charge_timer_input.state | int }}:00:00"
  entity_id: timer.ev_charge_timer

Toggle switch

A simple automation that turns on/off the swtich when timer events are fired, like this:

  • When timer.started --> switch on
  • When timer.finished --> switch off

Or you can just toggle the switch on any of those events.

Manually turn off

The cards allows to turn off the switch when you tap on it while running, but it doesn't finishes the timer o resets the input number. To make this work, add another automation that is fired when the switch if turned off and makes two things:

  • Sets the input number helper to zero
  • Finishes the timer helper

Lovelace card config

- type: conditional
  conditions:
    - entity: timer.ev_charge_timer
      state: idle
  card:
    type: custom:mushroom-number-card
    entity: input_number.ev_charge_timer_input
    name: Horas Carga
    fill_container: true
    display_mode: buttons
    layout: horizontal
    secondary_info: none
    icon_color: grey
- type: conditional
  conditions:
    - entity: timer.ev_charge_timer
      state_not: idle
  card:
    type: custom:timer-bar-card
    entity: timer.ev_charge_timer
    name: Coche Cargando...
    icon: mdi:ev-station
    mushroom:
      color: green
    tap_action:
      action: call-service
      service: timer.finish
      data:
        entity_id: timer.ev_charge_timer
    card_mod:
      style: |
        ha-card {
          background-color:#bce1b9
        }
        @media (prefers-color-scheme: dark) {
          ha-card {
            background-color:#344635
          }
        }
@kiryph
Copy link

kiryph commented Mar 14, 2025

Can you post the yaml code for the automations as well?

@luixal
Copy link
Author

luixal commented Mar 21, 2025

I guess is not that simple as I'm using Neopool for running this, but I've give it a try :)

Timer Input Execution

This automation starts the timer when a number is set.

alias: Piscina - Timer Execution
description: ""
mode: single
triggers:
  - entity_id:
      - input_number.my_timer_input
    above: 0
    trigger: numeric_state
conditions: []
actions:
  - target:
      entity_id: timer.my_timer
    data_template:
      duration: "{{ states.input_number.my_timer_input.state | int }}:00:00"
    action: timer.start

Timer Execution

This automation starts/stop a switch according to the timer.

alias: Piscina - Timer Execution
description: ""
mode: single
triggers:
  - event_type: timer.started
    event_data:
      entity_id: timer.pool_filtering_timer
    id: start
    trigger: event
  - event_type: timer.finished
    event_data:
      entity_id: timer.pool_filtering_timer
    id: finished
    trigger: event
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - start
        sequence:
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: switch.my_switch
      - conditions:
          - condition: trigger
            id:
              - finished
        sequence:
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: switch.my_switch
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: switch.my_switch

Turn on switch on HA boot

In case the switch doesn't keep its running state, this automation turns it on if timer is running when HA boots up.

alias: Piscina - Reanudar en Arranque HA
description: ""
mode: single
triggers:
  - event: start
    trigger: homeassistant
conditions:
  - condition: state
    entity_id: timer.my_timer
    state: active
actions:
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: switch.my_switch

Input Failsafe

This automation makes sure everything goes back to its off state when it has to.

alias: Piscina - Input Failsafe
description: ""
mode: single
triggers:
  - entity_id:
      - switch.my_switch
    to: "off"
    trigger: state
conditions: []
actions:
  - data:
      value: 0
    target:
      entity_id: input_number.my_timer_input
    action: input_number.set_value
  - data: {}
    target:
      entity_id: timer.my_timer
    action: timer.finish
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.my_switch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment