Coder Social home page Coder Social logo

homebridge-mqttswitch's Introduction

homebridge-mqttswitch

An homebridge plugin that create an HomeKit Switch accessory mapped on MQTT topics

Installation

Follow the instruction in homebridge for the homebridge server installation. The plugin is published through NPM and should be installed "globally" by typing:

npm install -g homebridge-mqttswitch

Release notes

Version 0.0.4 Dynamic Status

  • This new version uses an additional status command, sent via the "set" Topic, to dynamically retrieve the status of the switch from the device. The status should be then published by the device on the "get" topic, as usual. You should develop the device code to accept the status command on the "set" topic and answer publishing the actual status using the "get" topic. The status values must be the same used for the onValue and offValue configurations. This new version is able to detect the actual state of the device. This fixes also partially the issue #12. But, if the switch is off (I mean, the MQTT client is not responding to the status command) the best thing on the Home app is to put the device in a "No Response" state. You can't be sure that the device is really off, just think about a network problem, instead of a power problem. The method for this is not yet implemented in this version.

Version 0.0.3

  • Added onValue, offValue and integerValue params

Version 0.0.2

  • Initial public draft

Configuration

Remember to configure the plugin in config.json in your home directory inside the .homebridge directory. Configuration parameters:

  • "accessory": "mqttswitch",
  • "name": "PUT THE NAME OF YOUR SWITCH HERE",
  • "url": "PUT URL OF THE BROKER HERE",
  • "username": "PUT USERNAME OF THE BROKER HERE",
  • "password": "PUT PASSWORD OF THE BROKER HERE",
  • "caption": "PUT THE LABEL OF YOUR SWITCH HERE",
  • "topics": { "statusGet": "PUT THE MQTT TOPIC FOR THE GETTING THE STATUS OF YOUR SWITCH HERE", "statusSet": "PUT THE MQTT TOPIC FOR THE SETTING THE STATUS OF YOUR SWITCH HERE" }
  • "onValue": "OPTIONALLY PUT THE VALUE THAT MEANS ON HERE (DEFAULT true)",
  • "offValue": "OPTIONALLY PUT THE VALUE THAT MEANS OFF HERE (DEFAULT false)",
  • "statusCmd": "OPTIONALLY PUT THE STATUS COMMAND HERE"
  • "integerValue": "OPTIONALLY INCLUDE THIS TO USE 1/0 AS VALUES"

Note that if set, integerValue will override both onValue and offValue.

Look for a sample config in config.json example

homebridge-mqttswitch's People

Contributors

carlosra97 avatar ilcato avatar raidolo avatar suprajames avatar tvillingett avatar unixbigot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

homebridge-mqttswitch's Issues

Possible to use without username and password

Almost there for me:
I'm using a local mqtt broker, without username / pw, so I would like for it to be usable without.
Maybe both take care of no "user" parameter and with "" / NULL as user / password.

feedback from actual device?

Not so much an issue, more a request. But I'm not a Github regular so please redirect me if this is wrong.
I'm using mqtt switch on a pi with homebridge and mosquitto. Works very well. I connect to ESP8266 switches (reprogrammed Sonoff-switches) that return on or off to the Get Topic. So no matter if I press the switch on the ESP, send a publish to the set topic with a mqtt client, my iPhone will always reflect the right status. Except of course when the whole switch is offline. Then the iPhone will happily let me switch the device and tell me the switch is on while in reality it is not there at all...
Is there any way to check if the device actually returns the GetTopic before setting it to on/off?

Cannot read property 'replace' of null

Something is not ok with the MQTT server call...

Loading 1 accessories...
[mqtt_test_switch] Initializing mqttswitch accessory...
/usr/local/lib/node_modules/homebridge-mqttswitch/node_modules/mqtt/lib/connect/index.js:62
    opts.protocol = opts.protocol.replace(/\:$/, '');
                                 ^

TypeError: Cannot read property 'replace' of null
    at Object.connect (/usr/local/lib/node_modules/homebridge-mqttswitch/node_modules/mqtt/lib/connect/index.js:62:34)
    at new MqttSwitchAccessory (/usr/local/lib/node_modules/homebridge-mqttswitch/index.js:64:21)
    at Server._loadAccessories (/usr/local/lib/node_modules/homebridge/lib/server.js:175:29)
    at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:36:38)
    at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:23:16)
    at Object.<anonymous> (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

How to send "on" or "off" command

I have this set up with a sonoff device but I can only get "off" to work. When I flick the switch to on or off position in Home app it only ever send the off command. My sonoff is expecting cmnd/sonoff/power on and cmnd/sonoff/power off as topic and message. This works fine from command line mosquitto_pub but I can't for the life of me figure out the correct syntax in my config.json file to make this happen. Any ideas?

MQTT device status not updated in the HomeKit app

I'm working on a homemade ESP8266 device, able to interact with homebridge server thanks to the mqttswitch plugin.
Everything goes right if the homekit app ( eve or idevice in this case ) is up and running at the device change status time ( some port up or down as needed ) and the various homekit apps rightly show the port change status.
Unfortunately it's not true if the change occur when home kit apps was not running so that at the app start, it doesn't report the current/updated status of the device.
Maybe something related to the "statusGet" parameter but I'm unable to identify the issue even spying the various mqtt msg ( no "statusGet" topic fired ).

Please could you help/address me to solve the issue ?

Following you will find the accessories part of the config.json file for my setup :

"platforms": [
],

"accessories": [
    {
            "accessory": "mqttswitch",
            "name": "Light",
            "url": "mqtt://c1p8.lan",
            "username": "",
            "password": "",
            "caption": "light",
            "topics": {
                    "statusGet":    "salahobby/statusGet/1",
                    "statusSet":    "salahobby/statusSet/1"
                    }
    }
    ]

Thanks

[homebridge-mqtt.mqtt] config undefined or null!

I'm having this issue 'config undefined or null!'
homebridge sill note load

[10/9/2016, 7:04:52 PM] Loaded config.json with 1 accessories and 0 platforms. [10/9/2016, 7:04:52 PM] --- [10/9/2016, 7:04:52 PM] Loading 0 platforms... [10/9/2016, 7:04:52 PM] Loading 1 accessories... [10/9/2016, 7:04:52 PM] [MQTT_Test_Switch] Initializing mqttswitch accessory... Load homebridge-mqtt.mqtt [10/9/2016, 7:04:52 PM] [homebridge-mqtt.mqtt] config undefined or null! [10/9/2016, 7:04:52 PM] [homebridge-mqtt.mqtt] storagePath = /home/pi/.homebridge

here is my config.json

`"accessories": [
{
"accessory": "mqttswitch",
"name": "MQTT_Test_Switch",
"username": " ",
"password": " ",
"url": "mqtt://192.168.1.123",
"caption": "MQTT_Label",
"topics":
{
"statusGet": "switch1status",
"statusSet": "switch1command"
}
}
],

"platforms": [
]`

Getting error on startup "TypeError: Cannot read property 'length' of undefined"

/usr/lib/node_modules/homebridge-mqttswitch/node_modules/mqtt/lib/validations.js:42
  for (var i = 0; i < topics.length; i++) {
                            ^

TypeError: Cannot read property 'length' of undefined
    at Object.validateTopics (/usr/lib/node_modules/homebridge-mqttswitch/node_modules/mqtt/lib/validations.js:42:29)
    at MqttClient.subscribe (/usr/lib/node_modules/homebridge-mqttswitch/node_modules/mqtt/lib/client.js:417:30)
    at new MqttSwitchAccessory (/usr/lib/node_modules/homebridge-mqttswitch/index.js:89:17)
    at Server._loadAccessories (/usr/lib/node_modules/homebridge/lib/server.js:265:29)
    at Server.run (/usr/lib/node_modules/homebridge/lib/server.js:81:38)
    at module.exports (/usr/lib/node_modules/homebridge/lib/cli.js:40:10)
    at Object.<anonymous> (/usr/lib/node_modules/homebridge/bin/homebridge:17:22)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)

Just installed this plugin.
My config looks like this:

"accessories": [
    {
      "accessory": "mqttswitch",
      "name": "Sonoff1",
      "url": "mqtt://10.0.1.5",
      "username": "",
      "password": "",
      "caption": "Sonoff1",
      "topics": {
        "statusSet": "Sonoff1"
      },
      "onValue": "on",
      "offValue": "off"
    },
    {
      "accessory": "mqttswitch",
      "name": "sonoff2",
      "url": "mqtt://10.0.1.5",
      "username": "",
      "password": "",
      "caption": "sonoff2",
      "topics": {
        "statusSet": "sonoff2"
      },
      "onValue": "on",
      "offValue": "off"
    },
    {
      "accessory": "mqttswitch",
      "name": "sonoff3",
      "url": "mqtt://10.0.1.5",
      "username": "",
      "password": "",
      "caption": "sonoff3",
      "topics": {
        "statusSet": "sonoff3"
      },
      "onValue": 1,
      "offValue": 0
    }
  ]
}

MQTT Device status not updated in Homekit

Hi - i have an MQTT device which is connecting to a mosquitto broker. if I control the device solely through homekit the device status is correct in homekit, and is mirrored correctly in the device configuration url). However, if I change the device status via the device itself, or via its configuration app - the status isn't reflected similarly in homekit. It seems homebridge-mqttswitch isn't getting the device status correctly or subscribing to the update. Additionally, if the device is on and I restart homebridge, the correct status is not reflected in homekit.

I've pasted my homebridge setup below - is there any way I can enable extra logging to understand what's going on, or can you advise?

` "accessories": [
{
"accessory": "mqttswitch",
"name": "Gym Fan",
"url": "mqtt://localhost",
"username": "",
"password": "",
"caption": "Gym Fan",
"topics": {
"statusGet": "stat/sonoff/POWER",
"statusSet": "cmnd/sonoff/POWER"
},
"onValue": "ON",
"offValue": "OFF"

    }
]`

Thanks in advance.

Homekit doesn't read status correctly

I have a MQTT switch set up, with the config attached below. When I use the correct get topic, Homekit won't retain the switch being on (when I flip it to on on my phone, it publishes the right topic, but the switch on homekit instantly returns to "off", while the device is "on".


"accessory": "mqttswitch",
		"name": "Sonoff A1",
		"url": "mqtt://127.0.0.1",
		"username": "",
		"password": "",
		"caption": "Christmas Lights",
				"topics": {
			"statusGet": "stat/sonoffA1/POWER",
			"statusSet": "cmnd/sonoffA1/power"
		},
		"onValue": "ON",
		"offValue": "OFF",
		"integerValue": "false"

Unique code switch?

I’m using this plugin to open/close the garage door, using Sonoff RF Bridge flashed with Tasmota.
It’s the same rf code for both actions.

Can I configure this Home accessory to be returning to the off status after each press on the tile, and to fire the same code every time?

Please add Port option

Is possible add to this.options ... port option from homebridge config? I can edit source, but if you add this to your original souce, it will better way?

I have some problem with connecting to the mqtt broker. I added port number to url but, I don't know if is good idea.

Additional Info

Hi. Works great. Any chance of adding

		"manufacturer": "ITEAD",
		"model": "Mini",
		"serialNumberMAC": "Sonoff_C694C7",
		"firmware": "pkss1.0",

so it appears in Homekit if it's easy enough.

Cheers

How do I enable logging?

Trying to diagnose an issue where my device actual status isn't being updated (Sonoff). Read through the other issues but they all pre-date the current revision.

I see the code logs certain messages but I don't see it in syslog even with DEBUG= homebridge* set.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.