Trrying to turn a device off after a certain amount of time

Ok. So when I use the OPENHAB2 UI or Amazon dot, everything works as it should, Light turns on, and rule turns it off. The events can be seen in /var/log/openhab2/events.log

I have checked /etc/openhab2/services/mqtt-eventbus.cfg and there are only 4 values all of which are commented out.

#broker=
#statePublishTopic=
#commandPublishTopic=
#stateSubscribeTopic=
#stateSubscribeTopic=
#commandSubscribeTopic=

I’m guessing at the very least “Broker” needs a value.

Steve

But you have configured /etc/openhab2/services/mqtt.cfg, haven’t you ? You said it’s working properly with non-“Touch” model Sonoffs (without that you had to setup mqtt-eventbus). Based on that, your ‘standard’ (non-eventbus) mqtt.conf should be fine and you wouldn’t need to go for the eventbus extension.
Compare OH items and received MQTT messages of a working and the non-working switch. Check logging (with MQTT binding debug logging enabled, see previous post) what OH is doing when it gets to see messages from that ‘bad’ switch.

I havent checked /etc/openhab2/services/mqtt.cfg but will now.

I tried to find where I said it works with “Non Touch”, but cannot find it, However that was incorrect, i have the same problem with Sonoff basic and sonoff Dual, infact all my devices (which are all sonoffs0

The only setting that is set in mqtt.cfg is the broker

broker.url=tcp://localhost:1883

If I turn the device on from either the OH UI or Amazon Echo I get the following in the event log

2017-11-16 14:46:47.344 [ItemCommandEvent ] - Item ‘GarageLEDS’ received command OFF
2017-11-16 14:46:47.357 [ItemStateChangedEvent ] - GarageLEDS changed from ON to OFF

Also I have noticed the the devices internal Ui (if i go to its ip address), automatically updates the status of the device, which ever way i use to switch on the device.

Currently I can switch it on

  1. OH UI - Rules work OK - Sonoff UI updates
  2. Amazon Alexa - Rules work OK - Sonoff UI updates
  3. Hardware Switch on Sonoff - Rules dont work - sonoff UI updates
  4. Sonoff UI Rules dont work - sonoff UI updates

Well, that’s a different story then. Seems you haven’t configured OH MQTT binding properly yet (mqtt.conf) for in messages, wonder why you can control the switch from OH UI. Advice remains the same, though, see my previous post.

What is strange is, that no matter whether I have my user name and password in mqtt,cfg or not, everything works the same, its as if it isnt using mqtt.cfg

Lets try and simplify this to just 2 factors, one thats working and one that isnt.

OH UI When I click the “ON” button, MQTT,fx receives “ON”, turns the light on, an event is created and the rules turn it off - all good

Sonoff UI, when i click the “Toggle” button MQTT.fx also receives “ON” and turns the light on, but no event is created but the rules dont run.

I only had one subscription in mqtt.fx which was stat/sonoff-18/POWER.

Forgive my ignorance, but i thought if the message was getting to MQTT.fx identically for both operations, then OH should process both - am i missing something?

Your .items file you showed above appeared to only have outgoing mqtt messages configured.

Here is my Garage Lights, which are a Sonoff T1, and works perfectly both ways.

Switch Garage_Lights "Garage Lights"  <light> (Garage) { mqtt=">[mosquitto:cmnd/sonoff-garage-t1/POWER:command:*:default],
                                                               <[mosquitto:stat/sonoff-garage-t1/POWER:state:default]" } 

I have formatted it so that the outbound (>) and inbound (<) are on separate lines.

(Although, an earlier poster suggests I should also add “autoupdate=false” to the end - might this be why occasionally my lights have been switched on when I’ve gone back outside after turning them off…)

Problem sorted, I dont really know why. If someone can enlighten me that would be great

Notice the 2 item statements one has POWER in uppercase and one has it in lower case, the UPPERCASE one works OK.

Why would the upper case and lower case statements work OK to turn the lights on manually (or from UI), BUT only the lowercase one work to process the rules

Switch GarageLEDS “Garage LEDs” [ “Switchable” ] {mqtt=">[broker:cmnd/sonoff-18/POWER:command:OFF:0],>[broker:cmnd/sonoff-18/POWER:command:ON:1],<[broker:stat/sonoff-18/POWER:state:default]"}

Switch GarageLEDS “Garage LEDs” [ “Switchable” ] {mqtt=">[broker:cmnd/sonoff-18/power:command:OFF:0],>[broker:cmnd/sonoff-18/power:command:ON:1],<[broker:stat/sonoff-18/power:state:default]"}

Thanks Garry i think our messages must have crossed, like my solution you have POWER in UPPERCASE which i think was the issue

1 Like

Garry
Did you set switchmode or switch topic on the sonoff through the console ?

Did you configure the MQTT binding through PaperUI ?

The honest answer is I cannot remember, I am guessing not, because I have just had a look and cannot find a way to configure it. If i click on MQTT bindings, in the binding section it just takes me to a documentation page.

Just trying to tidy things up and its all stopped working againso trying to backtrack. switch

Why would “Switch” be green, is it an error or a “bug”

I don’t remember doing anything specific with the Sonoff after installing the Tasmota firmware.

Do you ever turn yours on/off from the sonoff web admin ?

Can’t say I have, other than maybe when I first installed Tasmota. After this, it was probably all from the device itself, or from OpenHAB. Are you having issues with this? I can give it a try over the next couple of days and check what the switch itself does, and what happens via MQTT/OpenHAB.

Its a strange one. I use MQTT.fx to see what MQTT messages are sent.

If I turn the sonoff on from the OPENHAB2 UI I get the following messages in MQTT.fx

If I turn the sonoff on from the sonoff UI (press TOGGLE) I get the following in MQTT.cfg
sonoffui

Notice the missing CMND message

cmnd is sent FROM openhab to the Sonoff.

stat is the feedback from the Sonoff TO openhab on its current state.

This is correct behaviour.

As per my first post above, these two things are defined against the Switch item, the “cmnd” is defined as outgoing FROM openhab TO Sonoff via the “>” symbol, and the “stat” is coming INTO openhab FROM the Sonoff.

Is OpenHABs UI responding and updating when you toggle it from the Sonoff web page?

Can you copy and paste EXACTLY what you’ve got in your .items file for this (make sure to put it within code fences using the button at the top of the reply box)

1 Like

Thanks for the “fences” tip

Switch GarageLEDS  "Garage LEDs" <poweroutlet> [ "Switchable" ]      {mqtt=">[broker:cmnd/sonoff-18/POWER:command:*default1],<[broker:stat/sonoff-18/POWER:state:default]"}