rstrouse / ESPSomfy-RTS-HA

Control your somfy shades in Home Assistant
The Unlicense
125 stars 9 forks source link

Send event infos to HA #14

Closed Pulpyyyy closed 1 year ago

Pulpyyyy commented 1 year ago

Hello

Does anyone thought of using events detected by the ESP's application to propagate them to HA (send cover ID + remote ID + key ID) ? For example, it could be used as a trigger in an automation: kind of human overlap/bypass.

Regards

rstrouse commented 1 year ago

There are a full set of services in the integration for control. I haven't messed around with the events but they are all the ones that are available to the cover domain.

Pulpyyyy commented 1 year ago

Hello. I was not thinking about services related to covers : all is working perfectly, but rather a new entity (sensor or input_text) that would update everytimes a remote control key is pressed (sending IDs as text). My main idea is to be able to make a différence between HA action (no entity update) and human ones (entity update)

rstrouse commented 1 year ago

Can you describe what you are trying to do? The events come from the ESPSomfy RTS device as the positions are computed. This also is reflected in the state associated with the entity. Would attributes on the entity help?

Pulpyyyy commented 1 year ago

Hello,

Normally, HA manages the shutter's position (heatwave, heliotropy, open in the morning, close in the evening). There are even a few comfort options for watching TV: in short, everything in automatic mode.

Now that the position of the shutters is always synchronized with the actual position (which wasn't the case with my rfxcom box), I'm very happy.

I'm now thinking of disabling automatic management of individually shutters, when the user has changed their position using the physical remote control (the others would still be managed in automatic mode). To do this, I'd need to be able to tell the difference between :

When it's a call via the api, it means HA is managing the shutters. When it's a call via the remote control, there's human intervention and so HA deactivates automatizations for this shutter.

Additionnaly, I'd need to know the identity of the shutter and, optionnaly, the command sent (up/my/down).

A simple json (which would simply be converted into an HA sensor, with attributes) like :

{
    state:"remote",
        "remote_id": "1234ABCD",
        "cover_id": "shutter1"
    "event_key": "up",
    "timestamp": 1234567890
}

or

{
    state:"api",
        "remote_id": "1234ABCD",
        "cover_id": "shutter1"
    "event_key": "up",
    "timestamp": 1234567890
}

or even

{
    state:"web",
        "remote_id": "1234ABCD",
        "cover_id": "shutter1"
    "event_key": "up",
    "timestamp": 1234567890
}

In my automation, i woulde able to use it as a trigger (with condition state == "remote" ) Do you see what i'm mean ?

Regards

rstrouse commented 1 year ago

ESPSomfy RTS knows whether it triggered the movement or something else triggered its movement.

How do you want to pull this information? Would state attributes on the HASS entity give you the function you need? That way you would not need to have a bunch of sensors floating around and it would get tagged specifically to the target entity. It could then also be in sync with the internal HASS clock and be used in templates. I suspect that would also make the automation as simple as looking at the attribute on the entity.

rstrouse commented 1 year ago

There may also be some weirdness with the my command. This is because my is also stop but I do know whether the my actually performed movement or simply stopped the motor at a position. Most of the time the actionable key is actually a stop command being issued but perhaps I can set this to only commands that created movement.

rstrouse commented 1 year ago

In addition to the state data that I have added to the entities, I will also forward the events to the hass event bus. I just need to figure out what to send. At a minimum I think I can send the event structure you have above.

EDIT: v2.0.1 contains the events you want. Look in the readme for details on the event.

Pulpyyyy commented 1 year ago

Sorry for my late reply. I'll look at the version 2.0.1 and will report ASAP. I think you last comment is quitte i have in mind. No need to have 1 sensor for 1 cover. Just 1 global sensor is enough, and updated with the latest event informations

Pulpyyyy commented 1 year ago

Wonderfull ! Here is test automation

alias: espsomfy-rts_event
description: ""
trigger:
  - platform: event
    event_type: espsomfy-rts_event
    event_data:
      source: remote
condition: []
action:
  - service: notify.notify
    data:
      title: "{{ trigger.event.data.event_key }}"
      message: >-
        Cover {{ trigger.event.data.name }} with ID {{
        trigger.event.data.entity_id }} received command {{
        trigger.event.data.command }}
mode: single

Screenshot_20230709_222507_One UI Home

Pulpyyyy commented 1 year ago

IMO issue can be closed, as feature is working perfectly. Many thanks !!!!

rstrouse commented 1 year ago

You are welcome. Closing issue.