esphome / esphome/feature-requests
Get result of homeassistant.service
- Dominant language
- No language data
- Stars
- 450
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the problem you have/What new integration you would like**
It's possible to call homeassistant services through the native API, but I don't see a way to know if that service call succeeded or failed.
**Please describe your use case for this integration and alternatives you've tried:**
I use Shelly 1L flashed with ESPHome behind my switches to control my smart bulbs :
```
- platform: gpio
name: Switch 2
pin:
number: GPIO14
internal: True
filters:
- delayed_on_off: 50ms
on_state:
- if:
condition:
binary_sensor.is_on: ha_connected
then:
- if:
condition:
switch.is_off: relayid
then:
- switch.turn_on: relayid
else:
- homeassistant.service:
service: light.toggle
data:
entity_id: light.mylight
else:
- switch.toggle: relayid
```
The goal is to transparently fallback to electrically toggling the relay if HA is down, which works okay (see caveat below).
But this does not address the case where HA is up and connected, but cannot control the light for any reason (maybe Z2M is down, or maybe the bulb didn't connect properly to the Zigbee network, it happens every once in a while).
It's possible for the service call to fail, which in the HA web UI does show an error, but as far as I can tell ESPHome does not know about. I'd love to be able to check the result of the service call, and toggle the relay if it failed.
As far as I can tell there's no way either to subscribe to events from the HA event bus, which could be another way to go about this (listen for the light state change event) maybe.
**Additional context**
I also noticed that the `status` platform sensor isn't great to know if HA is connected, it can be stale if HA crashed and will be on if the logs are being tailed, regardless of HA's status. Not directly related to this but if someone has a better way of knowing if HA is connected I'd be grateful.
I've seen someone use ping instead, but that doesn't sound like a good solution either, HA can be down even if the server pings.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.