this post was submitted on 29 Aug 2024
10 points (100.0% liked)

homeassistant

12080 readers
7 users here now

Home Assistant is open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server. Available for free at home-assistant.io

founded 1 year ago
MODERATORS
 

I have a Shelly dimmer 2 behind one of the switches in my kitchen running Tasmota. There are two switch inputs on the Dimmer module, so I have it behind a 2 gang wall box with two physical switches. Each switch is connected to one of the switch inputs of the Shelly.

I've set the switches to be independent of each other, so I can potentially use the different switches for different triggers. Switch one is configured as a push button switch and dims my kitchen lights. Switch two does nothing. I desire to have switch2 trigger my dining room lights, so after some digging I discovered that I can use MQTT to make Home Assistant do stuff! Perfect.

But not perfect. I set up an automation to listen for this devices' MQTT topic "tele/lights_kitchen/SENSOR" and when the switch is flipped either up or down, my mosquitto broker hears that topic, and it just toggles my lights! I thought I had it all figured out. But what I didn't notice at first, is that the Shelly Dimmer pings out an MQTT status every so often, even if no switches are flipped. So my dining room lights have been going on and off all afternoon!

There is some data in the payload of the MQTT that I think should be able to fix my issue, but I'm having trouble conceptualizing how.

The payload contains a key:value pair {"Switch2":"ON"} or "OFF". So I'm hoping I can use a change in that value as a toggle. Because it's operating as a 3 way switch, I don't care if the actual value is ON or OFF, I just want to know if it's changed. Do I need some sort of helper that keeps track? This seems like something MQTT would be good at, but I can't find a good example to steal the right config from. I thought maybe I could use two triggers, one for each state, but that makes a huge complicated set of logic that needs to be added, and I really feel like there should be a more elegant way to handle this.

Any assistance?

top 5 comments
sorted by: hot top controversial new old
[–] bastion@feddit.nl 1 points 2 months ago

There's a HACS integration called 'variable' that might help. Create the variable, then just:

  • check if variable equals switch state
    • if not, flip switch, and update the variable to the current switch state
[–] infeeeee@lemm.ee 1 points 2 months ago* (last edited 2 months ago) (1 children)

I'm not familar with shelly, but they don't use MQTT autodiscovery? If they use it you should have a corresponding HA entity or device of each switch. Then you can use built in tools or templates in automations, and don't directly mess with MQTT. That's much easier and stable.

If they don't use autodiscovery you can create HA entites via configuration.yaml manually

[–] Nimrod@lemm.ee 1 points 2 months ago

Yeah, Tasmota has 'setoption19' to enable autodiscovery, and I triggered it, and it finds a whole host of SENSORS - but none of them are the switches. It does add one entity which is a single switch. But it seems this just correlates to switch1. I'm thinking it has something to do with how I originally set up the dimmer... it was years ago, so I guess I need to dig into my notes and see if I can figure out what options I set on it before I moved it to it's current spot.

for reference, the data spit out by Tasmota: {"Time":"2024-08-29T15:17:19","Switch1":"OFF","Switch2":"OFF","ANALOG":{"Temperature":35.1},"ENERGY":{"TotalStartTime":"2021-07-13T17:05:01","Total":37178.152,"Yesterday":0.000,"Today":0.000,"Period":0,"Power":0,"ApparentPower":0,"ReactivePower":0,"Factor":1.00,"Voltage":117,"Current":0.000},"TempUnit":"C"}

[–] claude_flammang@dju.social 0 points 2 months ago (1 children)

@Nimrod Is there a specific reason not to use stock firmware with native Shelly integration? Then configure the input to edge mode.

[–] Nimrod@lemm.ee 1 points 2 months ago* (last edited 2 months ago)

Edit: I remember why - I wanted to use a single button dimming option, and as far as I can tell, there wasn't that option in Shelly natively. There isn't really a "native" version of this in Tasmota, but someone had already laid out the method to do such a thing with rules and whatnot within the Tasmota console. But after tinkering with it all this morning, I think I busted it beyond repair, so I might give the native Shelly a try!

Mostly because I'm lazy. This device was set up before Shelly made it so easy to run offline versions of the native firmware. And I've got a handful of devices already running Tasmota, so I'm just resistant to change.