Rule or script to detect states

Hello everybody,

I have a basic setup, and everything working fine, but, if I change the satet of a relay from outside of openhab, por example like MQTTfx, or physicaly activating the relay, the openhab does not detect the sate.

Is there any rule or script running behind that detect every change out of openhab?

I have thougth to write a rule where check the state in the broker and according this state, change the openhab visualization? Is that possible? :confused:

Thank you.

Is the binding installed? Check and post your mqtt.cfg
Use debug MQTT binding not connecting to mosquitto

Yes, MQTT binding installed.
Broker works fine, MQTTfx works fine, but I do not get any update in openhab.

In my /etc/openhab2/services/mqtt.cfg

mosquitto.url=tcp://192.168.2.123:1883
mosquitto.clientId=openhab
mosquitto.retain=true
mosquitto.async=false

Should I unistall/reinstall OH2?

What openhab-version on what system do you use?
Runs mosquitto on the same hardware as openhab?
Post a example of a item.

I installed on Monday Openhabian from the OH website, so I guess the last version.
mosquitto is runing on the same device.

Switch sonoff01 "LEDS" <light>
{ 
mqtt="
>[mosquitto:cmnd/sonoff01/POWER:command:ON:1],
>[mosquitto:cmnd/sonoff01/POWER:command:OFF:0],
<[mosquitto:sonoff01/POWER:state:MAP(onoff.map)]", update="false"}

What exactly does: do not get an update mean?
Did you look in the logs?
Does something come in?
Are there errors?

Everything works fine less when I control from MQTTfx or from the device I do not get un update, only that.

Items sitemaps works fine. Mosquitto works fine. But it seems that there is no link between broker and OH2 client.

I regret that the log does not work properly, I tried to load the log page and I get en error, and I have also tried with http://openhabianpi.local:9001/, without sucess. :confused:

Have you installed frontail to show the log on this way?

yes, from openhabian-config

ok, I have reinstalled frontail, now log is working under server.local.9001, this is the log. I do not use authentification.

==> /var/log/openhab2/openhab.log <==

2018-04-04 11:07:37.490 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://192.168.2.123:8080

2018-04-04 11:07:37.522 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at https://192.168.2.123:8443

2018-04-04 11:07:37.565 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = 380913da-73ab-47c2-b409-d9de603a82c0, base URL = http://localhost:8080)

2018-04-04 11:07:53.789 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.items'

2018-04-04 11:07:59.479 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui

2018-04-04 11:07:59.655 [WARN ] [penhab.io.transport.mqtt.MqttService] - Unrecognized property: mosquitto.usr

2018-04-04 11:07:59.659 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.

2018-04-04 11:07:59.661 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'

2018-04-04 11:08:00.167 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'

2018-04-04 11:08:00.498 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app

2018-04-04 11:08:03.164 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.rules'

2018-04-04 11:08:03.435 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007

2018-04-04 11:08:04.130 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.sitemap'

2018-04-04 11:08:04.709 [INFO ] [ui.habmin.internal.servlet.HABminApp] - Started HABmin servlet at /habmin

2018-04-04 11:08:04.940 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel

2018-04-04 11:08:05.664 [INFO ] [assic.internal.servlet.WebAppServlet] - Started Classic UI at /classicui/app

But sending from OH works?

Please use code fences for the log. Use the buttons above the textfield!

```   
your code goes here
```

I think you have a problem with you installation.
Without knowing what you have done it is painful to asking all details.
There are different raspian-versions.

I would start with a new installation unsing this way https://docs.openhab.org/installation/openhabian.html
and Raspberry Pi image v1.4.1 openHABian v1.4 released!

sorry.
yes from OH works fine.

Yes, I will try a new clean installation.
This is not working properly, at least the link between mosquitto and OH.

I will try v.1.4.1

Thanks.

Why do you have 2 mqtt-broker connections?

Please post the commands MQTTfx show.

good question, what the hell is that? But, in mqtt.cfg file I only have mosuitto.url. why the system tries to start other broker?

FYI: I had a openhabian version from 17.12. 2017. I am going to reinstll everything.

MQTTfx commands are:

cmnd/sonoff01/POWER PAYLOAD: ON/OFF
stat/sonoff01/POWER

and from MQTTfx is working fine, I get commanded and publish.

try

<[mosquitto:stat/sonoff01/POWER:state:MAP(onoff.map)]", update="false"}

thanks hr_2

I will try after resintall everything.

Why don’t you try @hr_2 suggestion before reinstalling everything. The binding did work ( switching worked) only the feedback from the device wasn’t configured correctly.

ok, I will try but at night before reinstall, because I have to go to work :smiley:
thank you for your help!!