I want to use a sonoff mini with esphome on a regulare push switch to controll a light group i have in home assistant.
I want it to be so if i “click” the switch i toggle the ligth group on and off, but if i hold the switch it “dims” to max and if i hold it again it “dims” to min.
That solution will not work for you as it is controlling devices directly wired to the ESP GPIOs. ESPHome does not have light groups. And there is no way to import a home assistant light into ESPHome.
You would have to write a similar ESP configuration that publishes a brightness sensor to Home Assistant. Then use an automation in home assistant to monitor this sensor for changes and addjst your light as required.
binary_sensor:
- platform: gpio
pin:
number: $button_gpio
name: $project Wall Switch
id: button
filters:
- delayed_on: 100ms
- delayed_off: 100ms
- delayed_on_off: 100ms
on_release:
- script.execute: hass_light_toggle
script:
- id: hass_light_toggle
then:
if:
condition:
api.connected:
then:
- if:
condition:
switch.is_off: relay
then:
# Turn the relay back on and turn on the light.
- switch.turn_on: relay
- homeassistant.service:
service: light.turn_on
data:
entity_id: $hass_light_1
transition: "3"
else:
# Have Home Assistant toggle the light.
- homeassistant.service:
service: light.toggle
data:
entity_id: $hass_light_1
transition: "3"
else:
# When HA is unavailable, toggle the relay.
- switch.toggle: relay
Relay is always on. But will toggle if not connected to home assistant. Which will turn lights on off lights that are connected to relay as dumb lights. Otherwise script will control smart lights via home assistant