- Platform information:
- Hardware: _ Raspberry Pi 3 Model B Rev 1.2_
- OS: Raspbian GNU/Linux 8 (jessie)
- Java Runtime Environment: (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76)
- openHAB version: OH 2.4.0.M5
- Bindings:Astro, AVM, EXEC, MQTT, Network, NTP, Samsung, Sonos, Weather (binding-weather1),MapDB-Persitence, http
- Transformations: exec, Javascript, JSONPATH, Map, RegEx, Scale
I read a lot in the Community blogs about Sonoff -Firmware and Firmware-Flashing. I have flashed several sonoffs via AtomIO and they are working in my openHAB-Setup. I was inspired by @ThomDietrich, @AndrewZ and of course Theo Arends and created the following setup to get some information:
sonoff.rules
val sonoff_device_ids = newArrayList("sonoffs")
rule "Sonoff Tasmota Version"
when
Item Dummy2 changed to ON or
Channel 'astro:sun:local:noon#event' triggered START
then
logInfo("sonoff.rules", "Tasmota Rel.Vers. set to Items: " )
for (String device_id : sonoff_device_ids) {
publish("peter", "cmnd/" + device_id + "/status", "2")
logInfo("sonoff.rules", "Sonoff Maintenance: " + device_id + " / " + sonoff_device_ids)
}
end
sonoff.items
//**********************************************************************************************************************************************************************************************************************
//POW Sensoren
//**********************************************************************************************************************************************************************************************************************
//192.168.178.62 Kugellampe
Switch Sonoff_Pow_01 "Kugellampe [MAP(de.map):%s]" <kugel1> (EG_Kind2,gLight,gSonoff) { mqtt=">[peter:cmnd/pow_01/power:command:*:default],
<[peter:stat/pow_01/POWER:state:default]" }
Number Sonoff_Pow_01_Verbrauch "Kugellampe Verbrauch Total[%.2f kWh]" <kugel1> (Chart_Sys_Temp) { mqtt="<[peter:tele/pow_01/SENSOR:state:JSONPATH($.ENERGY.Total)]" }
// For Fun and Test
Number Sonoff_Pow_01_Strom "Kugellampe Stromaufnahme [%.2f A]" <kugel1> (Chart_Sys_Temp) { mqtt="<[peter:tele/pow_01/SENSOR:state:JSONPATH($.ENERGY.Current)]" }
Number Sonoff_Pow_01_Spannung "Kugellampe Spannung[%.2f Volt]" <kugel1> (Chart_Sys_Temp) { mqtt="<[peter:tele/pow_01/SENSOR:state:JSONPATH($.ENERGY.Voltage)]" }
Number Sonoff_Pow_01_Leisung "Kugellampe Leistung[%.2f W]" <kugel1> (Chart_Sys_Temp) { mqtt="<[peter:tele/pow_01/SENSOR:state:JSONPATH($.ENERGY.Power)]" }
Number Sonoff_Pow_01_VCC "Kugellampe VCC[%.2f V]" <energy> (Chart_Sys_Temp) { mqtt="<[peter:tele/pow_01/STATE:state:JSONPATH($.Vcc)]" }
String Sonoff_Pow_01_State "Kugellampe Status [%s]" <chart> (Chart_Sys_Temp) { mqtt="<[peter:stat/pow_01/POWER:state:default]" }
Number Sonoff_Pow_01_RSSI "Kugellampe RSSI [%s]" <qualityofservice> (EG_Kind2,gRSSI) { mqtt="<[peter:tele/pow_01/STATE:state:JSONPATH($.Wifi.RSSI)]" }
String Sonoff_Pow_01_Tele "Kugellampe Wlan [%s]" <chart> (Chart_Sys_Temp) { mqtt="<[peter:tele/pow_01/STATE:state:JSONPATH($.Wifi.SSId)]" }
DateTime Sonoff_Pow_01_Date "Kugellampe Refresh [ %1$tH:%1$tM]" <clock> (Chart_Sys_Temp) { mqtt="<[peter:tele/pow_01/STATE:state:JSONPATH($.Time)]" }
String Sonoff_Pow_01_Version "Kugellampe Version [%s]" <sonoff_pow> (Chart_Sys_Temp,gVer) { mqtt="<[peter:stat/pow_01/STATUS2:state:JSONPATH($.StatusFWR.Version)]" }
//
Switch Dummy2 "Testschalter Dummy2 [%s]" (gPower)
String Sonoff_Current_FW_Available "Current Release available from Theo[%s]" <arendst> (Chart_Sys_Temp,gVer) { http="<[tasmotaRelease:10000:JSONPATH($[0].name)]"}
http.cfg
# configuration of the second cache item
# Tasmota Release Status (cached twice a day)
#<id2>.url=
tasmotaRelease.url=https://api.github.com/repos/arendst/Sonoff-Tasmota/tags
#<id2>.updateInterval=
tasmotaRelease.updateInterval=43200000
logInfo
2018-10-31 22:31:15.406 [INFO ] [.smarthome.model.script.sonoff.rules] - Tasmota Rel.Vers. set to Items:
2018-10-31 22:31:15.417 [INFO ] [.smarthome.model.script.sonoff.rules] - Sonoff Maintenance: sonoffs / [sonoffs]
and the result looks like this:
As i’m a newbie and do not understand Java and programming, i’m wondering how the rule works.
My first question:
From where does the rule know which are the “sonoffs” items (group topic) in the array ? I didn’t declared them anywhere. Is there a mechanism in openHAB to store it an can one see them with system tools ?
My second question:
As i understand the “for loop” looks in every sonoff (via the publish command) and the firmwareinformation comes back via the item-channel. and it loops as long as every topic in the array is passed?! Therefore i fill in the logInfo-Staetment in the" for-loop", but it’s only shown once, as in the above logger. in my IMHO it should be shown for every topic.
Maybe there is someone to explain me, my stupid questions ?
The next step for me will be to test the OTA-Update, but i’m a bit scared, because i’ve crashed one or two sonoff-basics, while trying to update them via the web-interface. (I tried it too with minimal-version and afterwards the normal,etc.)
There are a lot of more questions (validation of acuel firmware and device firmware), or what is the difference between “upload” and “upgrade” in the firmware commands ?
for me it looks like if it’s same.
If anyone can help me i will be very happy