jesserockz / wizmote-esphome

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code not optimised for multiple remotes.

TheAussieEngineer opened this issue · comments

wizmote.cpp having the following:
if (wizmote.sequence <= this->last_sequence_)
return;

prevents the effective use of multiple remotes. In short this bit of code will only allow the remote with the highest sequence to record events in HA. I recommend changing to the following:
if (wizmote.sequence == this->last_sequence_)
return;

This code will prevent rapid multi call of the events whilst also allowing multiple remotes to be used.

Someone had the same suggestion in the past here: #4 (comment)

Looks like it never made it into the code, though.

Someone had the same suggestion in the past here: #4 (comment)

Looks like it never made it into the code, though.

seen and good pickup. For anyone who it trying to used multiple remotes you can edit the file through the HA file editor (after the first time that the ESP has been updated). For me the file was at: /config/esphome/.esphome/external_components/343b74af/components/wizmote/wizmote.cpp

Looks like today Jesse merged my PR (#9 ) which fixes this and supports up to 15 remotes simultaneously (this limit is easily changed by modifying a define).

Het lijkt erop dat Jesse vandaag mijn PR (# 9 ) heeft samengevoegd, die dit oplost en tot 15 afstandsbedieningen tegelijkertijd ondersteunt (deze limiet kan eenvoudig worden gewijzigd door een definitie te wijzigen).

Hey, I have a question. I can't get the wizmote to work. I have an ESP32 with this code:

esphome:
  name: wizmote
  friendly_name: wizmote

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "secrid"

ota:
  password: "secrid"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Wizmote Fallback Hotspot"
    password: "secrid"

captive_portal:
    
external_components:
  - source: github://jesserockz/wizmote-esphome
    components:
      - esp_now
      - wizmote

esp_now:

wizmote:
  on_button:
    if:
      condition:
        lambda: return data.button >= 16 && data.button <= 19;
      then:
        - homeassistant.event:
            event: esphome.wizmote_choose
            data:
              mac: !lambda 'return format_hex(data.bssid, 6);'
              button: !lambda 'return data.button - 15;'
              sequence: !lambda 'return data.sequence;'
      else:
        - homeassistant.event:
            event: esphome.wizmote_action
            data:
              mac: !lambda 'return format_hex(data.bssid, 6);'
              button: !lambda 'return data.button;'
              sequence: !lambda 'return data.sequence;'

And I'm using the blueprint, but when I click on button 1, the lamp doesn't turn on. I've entered the correct MAC address, so what's wrong?

Let me take a look at my blue print. It's been several months since I did this change, but I seem to recall the stock blueprint didn't work as is after the change. Might be wrong with that. I'll test my known working setup against the stock blueprint and get back to you.

Let me take a look at my blue print. It's been several months since I did this change, but I seem to recall the stock blueprint didn't work as is after the change. Might be wrong with that. I'll test my known working setup against the stock blueprint and get back to you.

That's good because I really want to use it, especially with button 1 for single click, double click, and triple click; it would have a lot of options then!

As a note, I never made a blueprint that supports double or triple click. But there is technically no reason why it can't be made, but you'll need to make a blueprint for that one yourself.

The modifications I made to the blueprint simply allowed for a default group so if a group selection hasn't been made, it will default to whatever group I set. My wife got annoyed pressing the on button and the lights not turning on. So I just made the lights the default group for the blueprint

Let me take a look at my blue print. It's been several months since I did this change, but I seem to recall the stock blueprint didn't work as is after the change. Might be wrong with that. I'll test my known working setup against the stock blueprint and get back to you.

That's good because I really want to use it, especially with button 1 for single click, double click, and triple click; it would have a lot of options then!

Just finished testing the stock wizmote blueprint. It works just fine for me without any modifications. I also checked my esphome config against yours and it's also the same. So I don't think it's anything related to that.

So if yours isn't working, I would start with a simple debug in home assistant.

  1. Go to home assistant -> Developer tools -> Events
  2. Under "Listen for Events", type "esphome.wizmote_choose" and hit "Start Listening"
  3. On your remote, press any number, 1 to 4. You should see an event pop up containing the event information shown below:
image
  1. if this works, then make sure the mac field in the information here matches what mac you put into your automation.
  2. If this is not working, then I'd open up the ESPhome log view to your esp device. Make sure your log level is set to at least DEBUG. When you press any button on the remote, you should be greeted with a debug message that looks like this:
image

Laat ik eens kijken naar mijn blauwdruk. Het is enkele maanden geleden dat ik deze verandering heb gedaan, maar ik meen me te herinneren dat de voorraadblauwdruk niet werkte zoals na de verandering. Misschien is daar wel eens een misje mee. Ik zal mijn bekende werkopstelling testen aan de hand van de voorraadblauwdruk en contact met u opnemen.

Dat is goed, want ik wil het echt gebruiken, vooral met knop 1 voor enkele klik, dubbelklik en drievoudige klik; Het zou dan veel opties hebben!

Net klaar met het testen van de stock wizmote blauwdruk. Het werkt prima voor mij zonder aanpassingen. Ik heb ook mijn esphome config vergeleken met de jouwe en het is ook hetzelfde. Dus ik denk niet dat het daar iets mee te maken heeft.

Dus als de jouwe niet werkt, zou ik beginnen met een eenvoudige foutopsporing in de thuisassistent.

  1. Ga naar home assistant -> Developer tools -> Events
  2. Typ onder "Listen for Events" "esphome.wizmote_choose" en klik op "Start Listening"
  3. Druk op uw afstandsbediening op een willekeurig getal, 1 tot 4. U zou een gebeurtenis moeten zien verschijnen met de onderstaande gebeurtenisinformatie:
image 4. Als dit werkt, controleert u of het veld Mac in de informatie hier overeenkomt met de Mac die u in uw automatisering hebt geplaatst. 5. Als dit niet werkt, zou ik de ESPhome-logweergave openen naar uw esp-apparaat. Zorg ervoor dat uw logboekniveau is ingesteld op ten minste FOUTOPSPORING. Wanneer u op een knop op de afstandsbediening drukt, moet u worden begroet met een foutopsporingsbericht dat er als volgt uitziet: image

Hey, I found the issue. It was because I formatted my MAC address like this: '44.4F.8E.B0.0C.72', but it should be like this: '444f8eb00c72'. So, this isn't clear in the GitHub documentation. Now it's working perfectly. But now my question is, how can I assign different functions to button 1 for a single press, double press, and triple press so that I can add even more functionality? Do you have an explanation for this? I'm willing to create it myself, but I'm not sure where to find the right information.

Glad you found the issue.

Regarding the blueprint for detecting double clicks: the way that I would tackle it is the following:

The blueprint has a "choose" event listener. You can have a loop that triggers off additional choose events or an action event (up/down/sleep). Each trigger event contains a timestamp and the button pressed. So I would do the math to detect the time between presses from the timestamp flag and see if it is less than a double click threshold (maybe 0.5 second?). The blueprint mode will need to be single in order to detect this.

I am away from my home assistant instance for the rest of the week so I cannot take a stab at some logic.

I did some searching and found this thread about how to detect multiple clicks from a binary sensor. This is similar except it's a home assistant event and you will need to verify that the button press is the same as previously pressed.
https://community.home-assistant.io/t/trigger-different-actions-on-a-single-double-or-double-click-on-a-binary-sensor/255902