HASwitchPlate / openHASP-custom-component

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

Feature request: link event and properties between objects directly #61

Closed nagyrobi closed 5 months ago

nagyrobi commented 3 years ago

Is your feature request related to a problem? Please describe. Currently properties of an object can be linked only to values coming from entities in Home Assistant. We also need a way to directly link properties of an object to events coming from the (same) plate's other objects too.

Describe alternatives you've considered For example, I have a tabview with 3 tabs, and a label:

{"page":3,"id":26,"obj":"label","x":90,"y":220,"w":60,"h":30,"text":"#000000 \u2022# #909090 \u2022# #909090 \u2022#","text_font":24,"align":"center","text_color":"grey","border_width":0}
{"page":3,"id":30,"obj":"tabview","x":0,"y":235,"w":240,"h":80,"btn_pos":0,"bg_opa":0,"border_width":0,"radius":0}
{"page":3,"id":31,"obj":"tab","parentid":30}
{"page":3,"id":32,"obj":"tab","parentid":30}
{"page":3,"id":33,"obj":"tab","parentid":30}

Switching between the tabs is done by swiping left and right. The label shows 3 dots, the goal is to highlight the the dot corresponding to the tab.

kép kép kép

This can be achieved with some trickery:

      - obj: "p3b30"  # tab dots
        event:
          "changed":
            - service: mqtt.publish
              data:
                topic: hasp/plate_halo/command/p3b26.text
                payload: >
                  {% if val == 0 %}
                  {{ "#000000 \u2022# #909090 \u2022# #909090 \u2022#" | e }}
                  {%-elif val == 1 %}
                  {{ "#909090 \u2022# #000000 \u2022# #909090 \u2022#" | e }}
                  {%-elif val == 2 %}
                  {{ "#909090 \u2022# #909090 \u2022# #000000 \u2022#" | e }}
                  {% endif %}

Describe the solution you'd like Since data goes back to the same plate, something more efficient could be implemented, like:

      - obj: "p3b30"  # tab dots
        event:
          "changed":
            - obj_properties: "p3b26"
                "text": >
                  {% if val == 0 %}
                  {{ "#000000 \u2022# #909090 \u2022# #909090 \u2022#" | e }}
                  {%-elif val == 1 %}
                  {{ "#909090 \u2022# #000000 \u2022# #909090 \u2022#" | e }}
                  {%-elif val == 2 %}
                  {{ "#909090 \u2022# #909090 \u2022# #000000 \u2022#" | e }}
                  {% endif %}

Additional context https://discord.com/channels/538814618106331137/692393568266092617/852874097653186579 https://haswitchplate.github.io/openHASP-docs/0.6/integrations/home-assistant/sampl_conf/#generic-thermostatclimate

dgomes commented 3 years ago

The proposed solution would require a complete rewrite of the template engine...

I'm thinking about:

 - obj: "p3b30"  # tab dots
    event:
      "changed":
        - service: openhasp.update
          data:
            plate: openhasp.openhasp_plate_6fe4fc
            property: p3b26.text
            value: >
              {% if val == 0 %}
              {{ "#000000 \u2022# #909090 \u2022# #909090 \u2022#" | e }}
              {%-elif val == 1 %}
              {{ "#909090 \u2022# #000000 \u2022# #909090 \u2022#" | e }}
              {%-elif val == 2 %}
              {{ "#909090 \u2022# #909090 \u2022# #000000 \u2022#" | e }}
              {% endif %}
nagyrobi commented 3 years ago

Perhaps making the plate key optional, defaulting from the context to the current plate. So you only need to specify it if the object is on a different plate.

dgomes commented 3 years ago

Service really requires the plate….

On 12 Jun 2021, at 14:13, nagyrobi @.***> wrote:

 Perhaps making the plate key optional, defaulting from the context to the current plate. So you only need to specify it if the object is on a different plate.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

nagyrobi commented 3 years ago

Service really requires the plate

Sure, when outside the CC, in an automation. But when you parse it in your own code, you can substitute it (if none then self.plate etc.)

dgomes commented 3 years ago

Services are called using async_call_from_config (it reads directly from the yaml the service call)

I would need to patch the yaml file before calling... and would be confusing because we would have a service call in yaml that is different from the normal service call...

nagyrobi commented 3 years ago

I see

dgomes commented 3 years ago

If we can do without templates maybe something like:

bindings: p3b30.text: p3b26.text

And the cc would sync the two properties

nagyrobi commented 3 years ago

We need some kind of templates to be able to make it more universal. In the example above, we set the text property of an object based on the val property of another object.

nagyrobi commented 3 years ago

Well actually if you pull in the command service, that can already fulfill your logic the way it is - if it's not possible to make it more compact/efficient.

nagyrobi commented 2 years ago

This could be partially solved with https://github.com/HASwitchPlate/openHASP-custom-component/issues/63 .