@AndrewZ I’ve enhanced your rule a little bit so I can upgrade all modules at once. That is indeed a great addition! Thank you I’ll leave it to you to add it to the wiki.
val String filename = "sonoff.rules"
val sonoff_device_ids = newArrayList(
"sonoff-CBF6BE",
"sonoff-96504C",
...
)
rule "Sonoff Maintenance"
when
Item Sonoff_Action received command
then
logInfo(filename, "Sonoff Maintenance on all devices: " + receivedCommand)
for (String device_id : sonoff_device_ids) {
switch (receivedCommand) {
case "restart" :
publish("broker", "cmnd/" + device_id + "/restart", "1")
case "queryFW" :
publish("broker", "cmnd/" + device_id + "/status", "2")
case "upgrade" : {
publish("broker", "cmnd/" + device_id + "/otaurl", "http://sonoff.maddox.co.uk/tasmota/sonoff.ino.bin")
publish("broker", "cmnd/" + device_id + "/upgrade", "1")
}
}
}
Sonoff_Action.postUpdate(NULL)
end
Hehe, now all my modules are in perfect TELEPERIOD sync
Looking at the results again, why did we / I decide to go with the ArrayList? We could just have used the groups topic “sonoffs”! The list has the benefit, that a user could just as well only address one or a few modules. You think I should change it?
Exactly - array is more visual and flexible, we can simply comment/uncomment necessary modules in a rule.
I suppose you can just add a comment in wiki saying that this approach is shown as an alternative to ‘native’ grouptopic based scenario.
So, thanks for this excellent entry to the Sonoff Switches. I bought some Sonoff POWs exactly to monitor washing machine and dish washer states.
I have already flashed the arendst’s Sonoff-Tasmota firmware, got it up and running and it’s connected to the mosquitto-broker I installed on my OH2 openHABian.
So far, so good, but now I’m a bit lost on how to proceed next. How do I tell the POW to send power consumption, states and so on and how do I configure items in OH2 on this? I didn’t find some examples on this - or am I just blind!
Generic approach: use your mqtt client of choice to subscribe to all the topics; see what is coming from the device you working with; add an item in OH with mqtt binding, use the topic discovered earlier in the binding configuration.
You can use the RSSI example published by @ThomDietrich in wiki as a reference.
I have a question regarding a hardware modification of the Sonoff Touch. Does GPIO0 has to be connected to the ground all the time during flash process, or just until it enters a programming mode? And does connecting it to the ground means connecting that pin (GPIO0) to the earlier soldered pin header GND pin, or some other ground source?
Hi … a newbie here. Not sure whether the topic has been covered elsewhere. I have a Sonoff device with RF. Will the flashing impact the RF functionality?
Hi Andrew,
thanks for the help. As I’m new to the whole MQTT-stuff I’m a bit lost at how this will work and how it works within OH2. I can toggle my Sonoff Pow, but I don’t get the other information:
activated mqtt-binding and jsonpath in addons.cfg (binding=mqtt1, ..., transformation=jsonpath, ...)
configured the mqtt in OH2:
#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#
# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
#<broker>.url=tcp://<host>:1883
mqttoh2.url=tcp://localhost:1883
# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
mqttoh2.clientId=OH2MQTT
# Optional. User id to authenticate with the broker.
mqttoh2.user=m2m
# Optional. Password to authenticate with the broker.
mqttoh2.pwd=password
configured the Sonoff Pow to use the mosquitto Broker
1486464107: New connection from 192.168.xx.xx on port 1883.
1486464107: New client connected from 192.168.xx.xx as OH2MQTT (c1, k15, u'm2m').
1486464140: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
...
openhab.log
2017-02-07 13:15:13.566 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mqttoh2'
...
2017-02-07 13:20:41.229 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'sonoff.items'
2017-02-07 13:20:41.260 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
...
events.log
2017-02-07 13:23:44.652 [ItemCommandEvent ] - Item 'Sensoren_Status_SonoffDiWa' received command ON
2017-02-07 13:23:44.657 [ItemStateChangedEvent ] - Sensoren_Status_SonoffDiWa changed from NULL to ON
The switch toggles the Sonoff, but I don’t get updates on the power-consumption. Did I miss something?
You’re on the right way.
Make sure your Sonoff device is ether configured to send periodic updates or you’re asking it to report the data - see wiki.
I suggest to forget about OH for a moment and check what is reported by using the mqtt client:
mosquitto_sub -v -t 'tele/#' -t 'stat/#'
Hopefully you will see the json then you will just need to parse it properly.
TelePeriod | | Show current telemetry period in seconds
TelePeriod | 0 | off | Disable telemetry messages
TelePeriod | 1 | Reset telemetry period to ```user_config.h``` value
TelePeriod | <secs> | Set telemetry period between 2 and 3600 seconds
So I just figured, I could type in the “console” of the web-Frontend of the Sonoff Pow: TelePeriod 20, and it worked: