Marnix wrote: 
> 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.


------------------------------------------------------------------------
nenu's Profile: http://forums.slimdevices.com/member.php?userid=65867
View this thread: http://forums.slimdevices.com/showthread.php?t=113125

_______________________________________________
diy mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/diy

Reply via email to