Skip to content

Instantly share code, notes, and snippets.

@brunopk
Last active June 8, 2025 00:36
Show Gist options
  • Save brunopk/ef6eb3cb3a4696d1ba57bfd3375318f7 to your computer and use it in GitHub Desktop.
Save brunopk/ef6eb3cb3a4696d1ba57bfd3375318f7 to your computer and use it in GitHub Desktop.
Homa Assistant

Development

Reseting password on a local HA Python environment

  1. Delete config folder.
  2. Run scripts/setup again.
  3. Run HA.

AppDaemon

Tips

How to create an AppDaemon application and run it when clicking a button

Requirements:

Steps

  1. Create a helper with "Input button" type.
  2. Add a Button card to a dashboard:
      - show_name: true
          show_icon: false
          type: custom:button-card
          name: '#0000FF'
          entity: input_button.sc_button_blue
          show_state: false
          color_type: card
          icon: ''
          styles:
            card:
              - background: rgb(0, 0, 255)
              - color: white
          tap_action:
            action: perform-action
            perform_action: input_button.press
            target:
              entity_id: input_button.sc_button_blue
  3. Create the AppDaemon application :
    1. Define application in configuration file (usually in addon_configs/a0d7b954_appdaemon/apps/apps.yaml) :
      app_name:
          module: module_name
          class: YourApp
          button_id: input_button.sc_button_blue
    2. Add the Python code into addon_configs/a0d7b954_appdaemon/apps/module_name (the module name is defined in AppDaemon configuration YAML):
    3. import appdaemon.plugins.hass.hassapi as hass
      
      
      class ScApp(hass.Hass):
          """AppDaemon application to interact with SC RPI."""
      
          def initialize(self) -> None:
              """Initialize configurations."""
              entity_id = self.args["button_id"]
              state = self.get_state(entity_id, attribute="all")
      
              if state is not None:
                  actual_state = state["state"]
                  attributes = state["attributes"]
      
                  self.log(f"State: {actual_state}")
                  self.log(f"Attributes: {attributes}")
      
                  self.listen_event(
                      self.button_pressed_handler,
                      "state_changed",
                      entity_id=entity_id,
                  )
              else: 
                  self.log(f"get_state returned None for {entity_id}")
      
          def button_pressed_handler(
              self, event_name: str, data: dict[str, Any], **_kwargs: Any
          ) -> None:
              """Button press event handler."""
              self.log(f"Button event received event {event_name} and data {data}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment