Esp-radio icon indicating copy to clipboard operation
Esp-radio copied to clipboard

Fun: ESP-Radio + MQTT + OpenHAB Intergration

Open NonaSuomy opened this issue 8 years ago • 0 comments

Not cleaned up, but was having some fun hacking around with MQTT on the ESP-Radio and OpenHAB.

screenshot_20170428-004825

Updated...

2017-04-28-034846_773x965_scrot

/opt/openhab/conf/sitemaps/demo.sitemap

        Frame label="ESP-Radio Control" {
                Switch item=PlayerCTRL label="Controls" mappings=[1=Mute,2=Resume,3=Stop,4=Unmute]
                Selection item=ESPRadio_Station mappings=[0=Lounge, 1=Chill, 2=Boost, 3=Indie]
                Slider item=ESPVolume
                Text item=NowPlaying

/opt/openhab/conf/items/demo.items

Number PlayerCTRL                  "Controls"  <player>
Number ESPRadio_Station            "ESP Radio"      <network>     { mqtt=">[broker:espradio:command:*:preset=${command}]" }
Dimmer ESPVolume                   "Volume [%s %%]" <soundvolume> { mqtt=">[broker:espradio:command:*:volume=${command}]" }
String NowPlaying                  "Now Playing: [%s]" <keyring>   { mqtt="<[broker:espradio\nowplaying:state:default]" }

/opt/openhab/conf/items/demo.rules

rule "Player Controls"
        when
                Item PlayerCTRL received command
        then
                if(PlayerCTRL.state == 1)
                {
                        publish("broker","espradio","mute")
                }
                if(PlayerCTRL.state == 2)
                {
                        publish("broker","espradio","resume")
                }
                if(PlayerCTRL.state == 3)
                {
                        publish("broker","espradio","stop")
                }
                if(PlayerCTRL.state == 4)
                {
                        publish("broker","espradio","unmute")
                }
                PlayerCTRL.postUpdate(NULL)
end

GIST Code change

NonaSuomy avatar Apr 28 '17 05:04 NonaSuomy