HASwitchPlate / openHASP-custom-component

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

Feature request: allow condition in events #65

Closed nagyrobi closed 5 months ago

nagyrobi commented 2 years ago

Is your feature request related to a problem? Please describe. I'd like to display a message on the plate when a button is pressed, but only when the sun is up.

Describe the solution you'd like Use conditions, pretty much like in automations, in object events.

      - obj: "p2b2"  # light-switch toggle button warning
        event:
          "down":
            - condition: template
              value_template: "{{ (states('switch.plate_4_switch_12') == 'on' and state_attr('sun.sun','elevation') > 15) }}"
            - service: openhasp.command
              target:
                entity_id: openhasp.plate_4
              data:
                keyword: jsonl
                parameters: >-
                  {"page":2,"id":200,"obj":"obj","x":5,"y":55,"w":230,"h":160,"shadow_opa":140,"shadow_color":"black","shadow_width":20,"shadow_spread":0}
                  {"page":2,"id":201,"obj":"label","parentid":200,"x":10,"y":10,"w":215,"h":110,"text_font":24,"align":"center","text":"\uE595 It's daytime!\nPlease pull up\nthe covers instead!"}
                  {"page":2,"id":202,"obj":"btn","parentid":200,"x":20,"y":110,"w":190,"h":40,"text":"Thank you: a greener world","mode":"break","align":"center"}

Describe alternatives you've considered Putting this in a script outside the component. But this makes the whole thing very clunky if you have lots of things like this.

Additional context Add any other context or screenshots about the feature request here.

nagyrobi commented 1 year ago

@dgomes , conditions used in a similarly working component: https://github.com/aneeshd/schedule_state/blob/1b994009662faa6969cb33b629aaffa97d98cc41/custom_components/schedule_state/sensor.py#L368

akloeckner commented 11 months ago

In case this would be addressed: why not go and allow the full script syntax in that place? I'm sure the HA devs have some helper that makes this easy. Maybe even easier than "manually" iterating though a list of service calls.

Edit:

This seems to be a good template for using scripts in other components: https://github.com/home-assistant/core/blob/dev/homeassistant/components/template/switch.py