Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titleDockerfile
FROM oznu/homebridge

RUN npm install -g homebridge-nest
RUN npm install -g homebridge-sonoff-tasmota-http
RUN npm install -g homebridge-sonos
RUN npm install -g homebridge-http-temperature
RUN npm install -g homebridge-mqttthing
RUN npm install -g homebridge-cmd4
RUN mkdir ~/.homebridge
RUN mkdir ~/.homebridge/Cmd4Scripts
RUN cp /usr/local/lib/node_modules/homebridge-cmd4/Extras/Cmd4Scripts/State.js ~/.homebridge/Cmd4Scripts
RUN chmod 700 ~/.homebridge/Cmd4Scripts/State.js
RUN npm install -g homebridge-http-webhooks
RUN apk add jq


Running our Container

Code Block
docker run -d \
--restart=always \
--name homebridge \
--net host \
-e HOMEBRIDGE_INSECURE=1 \
-e HOMEBRIDGE_CONFIG_UI=1 \
-e HOMEBRIDGE_CONFIG_UI_PORT=8089 \
-p 8089:8089 \
-p 51826:51826 \
-p 51828:51828 \
-v /share/Volume/CONTAINERS/homebridge/conf:/homebridge \
-v /share/Volume/CONTAINERS/homebridge/plugins:/homebridge/plugins \
jmehan/homebridge

...

Code Block
titleconfig.json
...
{
                "accessory": "mqtt-switch-tasmota",
                "name": "sonoff97-2-relay",
                "url": "mqtt://192.168.1.60",
                "username": "john",
                "password": "pass",
                "topics": {
                        "statusGet": "stat/sonoff97-2/POWER",
                        "statusSet": "cmnd/sonoff97-2/POWER"
                }
},
...


Cmd4 Plugin

Here is an example that communicates to the nest developer api and pulls the humidity for a thermostat. It uses jq to parse the json returned.

Code Block
languagebash
titlesonoff158.sh
#TEMP on SONOFF 158
SOURCE_URL="http://192.168.1.158/cm?user=admin&password=xxx&cmnd=status%2010"
 
if [ "$1" = "Get" ]#Humidity

if [ "$1" = "Get" ]; then
   # $2 would be the name 'sonoff158spa'
   # $3 would be the charactersistic
 
   if [ "$3" = "CurrentTemperatureCurrentRelativeHumidity" ]; then

        temphumidity=`curl -v -L $SOURCE_URL |sed -rn 's/.*"Temperature":([0-9]*.[0-9]*).*/\1/p'`--location-trusted \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer xxx" \
        -X GET "https://developer-api.nest.com/" 2>/dev/null \
        | jq '.devices.thermostats."oFh5M-W1yNJjd1COACDoCrsH5zleG7kM".humidity'`

        echo $temp$humidity
      exit 0
   fi
 
   if [ "$3" = "StatusActive" ]; then
      echo "1"
      exit 0
   fi

fi
 
if [ "$1" = "Set" ]; then
  exit 1
fi

exit 0


References

...