Announcement

Collapse
No announcement yet.

ESP8266 Remote Volume Knob

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    ESP8266 Remote Volume Knob

    ESP8266 is a really cheap (<£5) microcontroller with built in WiFi. I loaded up a D1 Mini with ESPEasy and added a Rotary Encoder to make a Volume control.

    Click image for larger version

Name:	IMG_0714.jpg
Views:	1
Size:	235.4 KB
ID:	1578417

    Code:
    on System#Boot do
        TimerSet_ms,1,1
        Pulse,2,0,10
    endon
    
    on Rules#Timer=1 do
     
     Let,1,[Rotary#Count]
    
      if [Var#1]!=[Var#2]
         if [Var#1]>[Var#2]
            let,3,([Var#1]-[Var#2])*6
            sendtoHTTP,192.168.1.100,9000,/?player=Computer&p0=mixer&p1=volume&p2=%2b[Var#3]
        else
            let,3,([Var#2]-[Var#1])*6
            sendtoHTTP,192.168.1.100,9000,/?player=Computer&p0=mixer&p1=volume&p2=%2d[Var#3]
         endif
    
        Let,2,[Var#1]
        Pulse,2,0,10
        TimerSet,2,10
      endif
    
      TimerSet_ms,1,100
    endon
    
    on Rules#Timer=2 do
       Pulse,2,0,30
       DeepSleep,0
    endon
    Click image for larger version

Name:	Screen Shot 2020-10-26 at 18.12.36.png
Views:	1
Size:	100.5 KB
ID:	1578418

    I can provide more details if anyone is interested.

    Tony

    #2
    I understand the pieces-parts, but what would this be used for? A volume control of what and how?

    Comment


      #3
      Originally posted by meq123 View Post
      I understand the pieces-parts, but what would this be used for? A volume control of what and how?
      any LMS player (where volume has not been locked).
      Would allow you to put the volume controller anywhere convenient. It is configured to control a single nominated player.
      Paul Webster
      Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, ABC Australia and CBC/Radio-Canada
      and, via the extra "Radio Now Playing" plugin lots more - see https://forums.slimdevices.com/showt...Playing-plugin

      Comment


        #4

        I can provide more details if anyone is interested.

        Tony
        Yes please, looks like a nice lockdown project

        Cordialement, Strebor

        Comment


          #5
          More details:

          I used a D1 Mini that you can buy from Ebay / Amazon etc. There are various clones that are functionally equivalent.

          I used the experimental firmware in this post: https://www.letscontrolit.com/forum/...p=47456#p47456
          because it includes Wake on Lan. You will need a device driver: https://escapequotes.net/esp8266-wem...indows-driver/ or MAC https://kig.re/downloads/CH341SER_MAC.ZIP

          This is an easy tool to flash the firmware: https://github.com/marcelstoer/nodem...asher/releases

          If you have problems flashing, try a different USB lead.

          Have fun!

          Comment


            #6
            Originally posted by Wiredcharlie View Post
            More details:

            I used a D1 Mini

            Have fun!
            Thanks, I found the Rules tutorial pages on the easy site. I'll hack about with one of the esp's I've got in the gache box..
            Strebor

            Comment


              #7
              Awesome project!

              I have a few questions. How does the player start the playback when your turn on volume? Have you set it up from lms settings?

              And is it possible to use the push button on the rotary encoder to change a song? Do you have a code for that?

              And I guess it is not battery powered?

              Thanks!
              test

              Comment


                #8
                another Wemos D1 mini controller

                this inspired me to finally solve a long standing (minor) frustration I had.

                We have 3 squeezeboxes in the main living area (1x Touch, 1x Radio and 1x Receiver). The Receiver is connected to another 'receiver', but this one a of the home theater Onkyo variety. Both receivers are connected to ethernet and are hidden out of view. However since the power consumption is a bit high, the Onkyo receiver is set to automatically shut down. But getting it running again requires pushing the power button, connecting over the network with an app or using the IR remote. So while installing it, I figured having a separate IR 'receiver' (this may be getting confusing) semi-hidden, but with a line of sight, would be OK. However, the IR remote ends up in the same cupboard as the (Onkyo) receiver itself and it's usually too much of a hassle to get it out. In practice, and this was the frustration, the Onkyo receiver was rarely used and that zone was covered by very one-sided sound from the Radio instead.

                Based on the parent post, I ordered a Wemos D1 mini. I intended to directly send commands to LMS and the Onkyo similar to what Wiredcharlie proposed. However, it turns out the Onky doesn't listen to HTTP or UDP, only TCP, which isn't available in ESPEasy. And since I got a ~1 EUR screen (0.96" OLED) with the D1, it would be nice to have some feedback on that as well. So in the end I had to go with this configuration:
                Wemos D1 mini <--> MQTT broker <--> Home Assistant <--> LMS | Onky Receiver
                with the MQTT broker, Home Assistant and LMS all running as containers on a NanopiNeo3. I am sure a more efficient approach is possible, but with my very limited understanding of the ESP, linux and all the protocols, this is what I finally got working.

                I managed to fit the Wemos D1 mini in a standard light switch faceplate. The central area is 45x45mm with a ~70mm wall box. It fits just barely. I had to modify (cut away) some of the metal bits from the frame, which is now far less rigid, but sufficient for this use. Since my machining skills are nonexistent, I oversized the hole for the screen and covered the rough edges with a 3D printed bezel. WAF is good enough.
                Power is through a long USB cable from a USB port on a wifi access point mounted in the ceiling. That also provides console/serial access to the D1 (this was an afterthought).

                Functionality is:
                - rotation: volume up/down (max. limit for each player hard coded in Home Assistant)
                - single click: switch between 3 players (to set individual volumes)
                - double click: toggle play/pause
                - long click: toggle Onkyo receiver on/off

                Anyway, thanks Wiredcharlie for the idea, and everyone else here for keeping the squeezeboxes working and very relevant.

                Wouter

                Click image for larger version

Name:	3_TestOpstelling.jpg
Views:	1
Size:	69.2 KB
ID:	1570773Click image for larger version

Name:	5_SAM_1957.jpg
Views:	1
Size:	74.8 KB
ID:	1570774Click image for larger version

Name:	8_SAM_1968.JPG
Views:	1
Size:	198.2 KB
ID:	1570775

                Comment


                  #9
                  Building instcructions?

                  Wouter,

                  this is really impressive, and a nicely mounted!

                  It would be really nice and informative if you could share some of your code and/or design decisions.

                  For me i'm very curious to see where you put the logic for al the push and turn options? single click, double, long enz

                  And how do you get the info from the lms on your oled display?

                  Marnix

                  Comment


                    #10
                    Originally posted by Marnix View Post
                    It would be really nice and informative if you could share some of your code and/or design decisions.
                    To be honest, design decisions were based on what I could get to work with my limited knowledge.

                    For me i'm very curious to see where you put the logic for al the push and turn options? single click, double, long enz
                    I found following limitations in ESPEASY and Home Assistant:
                    - ESPEASY can't use TCP to talk to the receiver, hence the need for Home Assistant
                    - ESPEASY can't seem to store strings that are sent to it over MQTT, hence the player names are hard-coded on the ESP
                    - Home Assisant can only understand 1 variable parameter in an MQTT message, so sending player id or name together with a volume change isn't possible. I made seperate MQTT channels for each player.

                    Regarding the actions:
                    - The 'change player' action is handled on the ESP. The ESP keeps track of which player it is controlling, updates the display. It also requests an update of the volumes, just in case.
                    - Volume change is sent to Home Assistant as +1 or -1, which HA then converts into an absolute value and sends to LMS.
                    - play/pause and powering on the receiver also sent to HA.

                    And how do you get the info from the lms on your oled display?
                    Upon any of the volumes changing, HA sends an update. That MQTT message triggers an update of the screen on the ESP. This also happens if the state is changed by any other means (e.g. on the players themselves).
                    There is some obvious lag in volume changes becoming effective , but not too bad.

                    It works pretty well, but I am not entirely happy with how the logic is split over the ESP and HA, and how I had to hard-code the player names in the ESP. I am considering experimenting with micropython, which should it make possible to communicate to LMS and the receiver directly and, more importantly to put all logic on the ESP itself.

                    ESPEASY rules:
                    Code:
                    on System#Boot do
                      let,1,0    // volume of player 1 (Veranda)
                      let,2,0    // volume of player 2 (Keuken)
                      let,3,0    // volume of player 3 (Veranda)
                      let,4,0    // state of receiver
                      let,5,1    // player being controlled
                      let,10,0
                      let,15,1   // timeout keeper for rotary encoder
                    endon
                    
                     // on MQTT#Connected do
                     //   Publish,ESPStatusUpdate/status,request
                     // endon
                    
                    on UpdateDisplay do
                      if [VAR#5]=1
                        oledframedcmd,1,"Veranda"
                        oledframedcmd,2,[VAR#1#F]%
                        oledframedcmd,3,"Receiver [VAR#4#O]"
                      elseif [VAR#5]=2
                        oledframedcmd,1,"Keuken" 
                        oledframedcmd,2,[VAR#2#F]%
                        oledframedcmd,3,""
                      elseif [VAR#5]=3
                        oledframedcmd,1,"Living"
                        oledframedcmd,2,[VAR#3#F]%
                        oledframedcmd,3,""
                      else
                        oledframedcmd,1,"ERROR"
                      endif
                      oledframedcmd,Display,on
                    endon
                    
                    on MQTTfromHASS do
                      oledframedcmd,3,"MQTT"
                      Let,1,%eventvalue1%*100
                      Let,2,%eventvalue2%*100
                      Let,3,%eventvalue3%*100
                      Let,4,%eventvalue4%*100
                      asyncevent,UpdateDisplay
                    endon
                    
                    on Switch#State=1 do
                      timerSet,2,1
                    endon
                    
                    on Rules#Timer=2 do
                      if [VAR#5]=1
                        let,5,2
                      elseif [VAR#5]=2
                        let,5,3
                      elseif [VAR#5]=3
                        let,5,1
                      endif
                      asyncevent,UpdateDisplay
                    endon
                    
                    on Switch#State=3 do
                      timerSet,2,0
                      Publish,ESPStatusUpdate/play,[VAR#5#F]
                    endon
                    
                    on Switch#State=11 do
                      timerSet,2,0
                      if [VAR#4]=0
                        let,5,1
                      endif
                      asyncevent,UpdateDisplay
                      Publish,ESPStatusUpdate/receiver,toggle
                    endon
                    
                    on Rules#Timer=1 do
                      let,15,1
                      let,11,[Rotary#Counter]  
                    endon
                    
                    on Rotary#Counter do
                      if [VAR#15]=1
                        let,10,[Rotary#Counter]
                        let,12,[Var#10]-[VAR#11]
                        let,11,[VAR#10]
                        Publish,ESPStatusUpdate/volume[VAR#5#F],"[VAR#12#F]"
                        asyncevent,UpdateDisplay
                        Let,15,0 
                        timerSet,1,1   
                      endif
                    endon
                    Suggestions very welcome, obviously.

                    Comment

                    Working...
                    X