HASwitchPlate / openHASP-custom-component

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

Feature request: wrapper service for any command #50

Closed nagyrobi closed 3 years ago

nagyrobi commented 3 years ago

Is your feature request related to a problem? Please describe. openHASP supports a handful of commands. Some of them would be useful in HA automations, like setting dim values or change theme based on day/night, etc.

Instead of having services in HA translated to each command, we could use one single service which could wrap them all in one.

Describe the solution you'd like A universal service which would accept 2 or 3 parameters:

    - service:  openhasp.command
      target:
        entity_id: openhasp.plate35
      data:
        command: 'config'
        keyword: 'gui'
        parameters: '{"idle2":0}'

If the config or any other commands except command would be deprecated, only the keyword and parameters would suffice.

Describe alternatives you've considered Sending commands directly to the plate is currently possible outside the component like this example:

    - service: mqtt.publish
      data:
        topic: hasp/plate35/config/gui
        payload: '{"idle2":0}'

Instead of this, it would be a lot better to wrap this inside the component like above, as they can be used with automations and blueprints more consistently. You can reference to a plate universally using it's entity_id, instead of having to keep separately track of MQTT topics belonging to that plate.

Additional context Extra benefit is that commands list can freely change on the firmware side, the component doesn't have to implement new services for them if they are requested, changed or added.

nagyrobi commented 3 years ago

Next and prev page services could be replaced with this, as the firmware supports directly these commands.

The number of services could be reduced with this.

nagyrobi commented 3 years ago

After applying the PR, some examples (no need to know the node name):

Jump to page:

service: openhasp.command
data:
  keyword: page
  parameters: '1'
target:
  entity_id: openhasp.plate_3

Next page:

service: openhasp.command
data:
  keyword: page
  parameters: 'next'
target:
  entity_id: openhasp.plate_3

Set Long idle time:

service: openhasp.command
data:
  keyword: '{"idle2":120}'
  command: config/gui
target:
  entity_id: openhasp.plate_3

Draw BSOD:

service: openhasp.command
data:
  keyword: jsonl
  parameters: >-
    {"page":0,"id":99,"obj":"obj","x":0,"y":0,"w":240,"h":320,"radius":0,"hidden":0,"bg_grad_dir":0,"bg_color":"blue"}
target:
  entity_id: openhasp.plate_3

Delete BSOD:

service: openhasp.command
data:
  keyword: p0b99.delete
target:
  entity_id: openhasp.plate_3
dgomes commented 3 years ago

keyword is very misleading, specially in the "Set long idle time" example

fvanroie commented 3 years ago

I'm thinking along the lines of raw mqtt messages like:

service: openhasp.publish
data:
  topic: command/jsonl
  payload: >-
    {"page":0,"id":99,"obj":"obj","x":0,"y":0,"w":240,"h":320,"radius":0,"hidden":0,"bg_grad_dir":0,"bg_color":"blue"}
target:
  entity_id: openhasp.plate_3

to send anything without validation.

Other more specific services can handle specific commands with input validation as required.

dgomes commented 3 years ago

this just slightly better then mqtt.publish...

I would keep the "command" instead of topic and a list of available commands for validation

nagyrobi commented 3 years ago

Thank you. openhasp.command and openhasp.config services fulfill this request.