Rule or script to detect states

I have got some progress. After try what hr_2 posted, I do not get that OH get states updated.
I decided to reinstall everything. OH and Mosquitto are running ok, everythim I release a command from MQTTfx, I got a message in the OH log, and it seems that something in the onoff.map is wrong

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

2018-04-04 22:55:33.363 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://192.168.2.123:8080
2018-04-04 22:55:33.396 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at https://192.168.2.123:8443
2018-04-04 22:55:48.905 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.items'
2018-04-04 22:55:52.299 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2018-04-04 22:55:55.349 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.rules'
2018-04-04 22:55:56.770 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home_vis.sitemap'
2018-04-04 22:55:56.819 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.sitemap'
2018-04-04 22:55:58.815 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-04-04 22:55:58.818 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'
2018-04-04 22:55:59.413 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-04-04 22:55:59.867 [INFO ] [assic.internal.servlet.WebAppServlet] - Started Classic UI at /classicui/app
2018-04-04 22:55:59.943 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-04-04 22:56:00.101 [INFO ] [ui.habmin.internal.servlet.HABminApp] - Started HABmin servlet at /habmin
2018-04-04 22:56:00.581 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2018-04-04 22:57:43.053 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'home.items'
2018-04-04 22:57:43.116 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'home.items'
2018-04-04 22:59:55.216 [ome.event.ItemCommandEvent] - Item 'sonoff04' received command ON
2018-04-04 22:59:55.281 [WARN ] [rm.AbstractFileTransformationService] - Could not transform 'ON' with the file 'onoff.map' : Target value not found in map for 'ON'
2018-04-04 22:59:55.284 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'sonoff04'

So, I had this in the onoff.map

0=OFF
1=ON

But it was not enough, SO, I decided to change them to:

OFF=OFF
ON=ON
NULL=OFF

AAANNNDD NOW IT IS WORKING!!! :smiley:

Thank you for your help!!

In this case you would not need a map transformation. As your commands are already on and off.

I thought about it, but what happend with NULL? I got a warning in the log… Well, I will try

Yeah NULL. But do you get NULL states?

Yes, I did get but I think only when I reboot and turn on/off switches first time, after one cycle of ON/OFF I do not get NULL states anymore, … that is why I wrote NULL in the onoff.map

2018-04-04 22:59:55.284 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'sonoff04'

I think this can be ignored then, but this is just my opinion.
Just on a gut level i would expect faster processing without map.