Recent build of 2.0.0-SNAPSHOT has remove the NullPointerException issue, thanks.
I test 2 LED in ESP8266-12E NodeMCU board, one is via GPIO2 to sent â0â to turn on the on board LED, other one is via GPIO12 to sent â1â to turn on external LED. I modified the item file:
Switch LED02 {mqtt=">[mosquibroker:/ESP_Easy_01/GPIO/2:COMMAND:ON:MAP(onoff_inverse.map)],>[mosquibroker:/ESP_Easy_01/GPIO/2:COMMAND:OFF:MAP(onoff_inverse.map)],<[mosquibroker:/ESP_Easy_01/GPIO/2:state:MAP(onoff_inverse.map)]", autoupdate="false"}
Number LED02_Status {mqtt="<[mosquibroker:/ESP_Easy_01/GPIO/2:state:MAP(onoff_inverse.map)]"}
Switch LED12 {mqtt=">[mosquibroker:/ESP_Easy_01/GPIO/12:COMMAND:ON:MAP(onoff.map)],>[mosquibroker:/ESP_Easy_01/GPIO/12:COMMAND:OFF:MAP(onoff.map)],<[mosquibroker:/ESP_Easy_01/GPIO/12:state:MAP(onoff.map)]", autoupdate="false"}
Number LED12_Status {mqtt="<[mosquibroker:/ESP_Easy_01/GPIO/12:state:MAP(onoff.map)]"}
and the rule file (I use function to unify switch rule):
//Function 1: Switch State Update
val org.eclipse.xtext.xbase.lib.Functions$Function SwitchLogic = [
org.openhab.core.library.items.SwitchItem SwitchItem,
org.openhab.core.library.items.SwitchItem SwitchState |
if (SwitchState.state == ON) SwitchItem.postUpdate(ON)
else SwitchItem.postUpdate(OFF)
]
//Function End
rule "LED02 State Update"
when
Item LED02_State received update
then
SwitchLogic.apply(LED02, LED02_State)
end
rule "LED12 State Update"
when
Item LED12_State received update
then
SwitchLogic.apply(LED12, LED12_State)
end
and the transform map:
onoff_inverse.map :
1=OFF
0=ON
1.00=OFF
0.00=ON
OFF=1
ON=0
OFF=1.00
ON=0.00
onoff.map :
0=OFF
1=ON
0.00=OFF
1.00=ON
OFF=0
ON=1
OFF=0.00
ON=1.00
and the sitemap:
Frame label="MQTT Test"{
Switch item=LED02 label="LED 02"
Switch item=LED12 label="LED 12"
}
When I turn on/off LED 02, the log shows:
14:04:36.065 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'LED02' received command ON
14:04:36.080 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'LED02_Status'
14:04:36.089 [INFO ] [marthome.event.ItemStateChangedEvent] - LED02 changed from OFF to ON
14:04:38.278 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'LED02' received command OFF
14:04:38.286 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'LED02_Status'
14:04:38.289 [INFO ] [marthome.event.ItemStateChangedEvent] - LED02 changed from ON to OFF
14:04:38.380 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'LED02_Status'
LED 02 works properly, even I manual change GPIO pin status from ESP8266, the LED status on my mobile openhab app change immediately and correctly.
But for example, if I change onoff_inverse.map to:
1=OFF
0=ON
the log is:
14:02:23.292 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'LED02' received command ON
14:02:23.300 [WARN ] [rm.AbstractFileTransformationService] - Could not transform 'ON' with the file 'onoff_inverse.map' : Target value not found in map for 'ON'
14:02:23.306 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '' with the file 'onoff_inverse.map' : Target value not found in map for ''
14:02:23.309 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'LED02'
14:02:23.310 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '' with the file 'onoff_inverse.map' : Target value not found in map for ''
14:02:23.313 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'LED02_Status'
14:02:23.443 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '0.00' with the file 'onoff_inverse.map' : Target value not found in map for '0.00'
14:02:23.445 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'LED02'
14:02:23.447 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '0.00' with the file 'onoff_inverse.map' : Target value not found in map for '0.00'
14:02:23.450 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'LED02_Status'
and if I change onoff_inverse.map to:
1=OFF
0=ON
1.00=OFF
0.00=ON
then the log is:
14:02:30.168 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'LED02' received command OFF
14:02:30.174 [WARN ] [rm.AbstractFileTransformationService] - Could not transform 'OFF' with the file 'onoff_inverse.map' : Target value not found in map for 'OFF'
14:02:30.192 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '' with the file 'onoff_inverse.map' : Target value not found in map for ''
14:02:30.196 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'LED02'
14:02:30.199 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '' with the file 'onoff_inverse.map' : Target value not found in map for ''
14:02:30.204 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'LED02_Status'
My question is: Dose the format of MAP file is OK? and, Can you give me some advice on âFunctionâ? Like: How to fully qualify each and every reference with the complete package name?
Thank a lot!