HASwitchPlate / openHASP-custom-component

Home Assistant custom component for openHASP
https://www.openhasp.com
MIT License
51 stars 12 forks source link

Question/Feature: Plate MQTT Name from inside template inside Event Handler? #92

Closed erwin closed 3 weeks ago

erwin commented 2 years ago

Assuming we start with the "Simple Page Navigation" openHASP example...

Perhaps this is already possible, but I haven't figured out a way to make it work.

Let's say I have:

# configuration.yaml
openhasp:
  plate_foo:
    objects: !include openhasp.yaml
  plate_bar:
    objects: !include openhasp.yaml
  plate_baz:
    objects: !include openhasp.yaml
# openhasp.yaml
     - obj: "p0b2"            
       event:            
         "down":             
           - service: persistent_notification.create
             data:                         
                message: Some way to get plate name? Maybe inside {{ state.state }}                

My goal is to handle the "home" (back) action via home-assistant, rather than via the built in openhasp action:back function.

image

This way I can have plates in different rooms that start on their own "default" page, but keep all of the configuration global.

When pressing "home" on the master bedroom plate, home would be page 1 (the default). But when pressing "home" on the entry plate, home would actually be page 4 And "home" on the living room plate would be page 3.

It's straight forward to send the "go to page" function but no idea how I can get the current plate name.

  - obj: "p0b2"                                                                    
    event:                             
      "down":               
        - service: mqtt.publish
          data:
            topic: hasp/{{ HOW DO I GET THE PLATE NAME }}/command/page
            payload: '5'

Since the openhasp-custom-component is just responding to an MQTT request, the custom component must know which plate is involved to dispatch to the correct event handler, but I haven't figured out how to pull that into a template to respond with an MQTT message back to that same plate.

nagyrobi commented 2 years ago

See https://github.com/HASwitchPlate/openHASP-custom-component/issues/63 If we had a way to set variables in the config, this could be addressed too...

erwin commented 2 years ago

@nagyrobi yes, I saw your request about variables before I posted, and I agree that more general purpose variables would be awesome, I posted this because I think page based navigation does also support "reuse" (all plates can have all the same page numbers, just choose a different "default page" and skip pages that are not relevant for that plate).

If it's not already possible, might be much easier to implement that a fully variable driven config.

fvanroie commented 3 months ago

I believe this issue can be resolved by using the tag property on the button and set it to the platename. The tag is sent along in the event, so you can leverage that functionality for this too.