Have a MAME box with to many games
Want the Screen to come on when I walk up to it
shopping List
https://www.itead.cc/sonoff-wifi-wireless-switch.html
only needs 3.3v to run
red = 3.3v
yellow = GPI0 14
Black = GND
Flash the Sonoff with Tasmota 5.14
So I see the MQTT messages I setup GPI03 as a Relay2 (dummy one)
GPIO14 as Switch2
back to main screen
check the Log
looks good
now only problem is it send a ON them a OFF comand so I used nodered
The Nodered code
[{"id":"4695784b.b0ae88","type":"mqtt in","z":"d664133d.f572c","name":"MAME Motion","topic":"stat/MAME/POWER2","qos":"2","broker":"987c4047.b2d81","x":90,"y":360,"wires":[["aac420af.2c7df"]]},{"id":"69e6eee8.548e2","type":"debug","z":"d664133d.f572c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":420,"wires":[]},{"id":"9b992535.2929c8","type":"delay","z":"d664133d.f572c","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":120,"y":480,"wires":[["792b35c4.6d4e7c"]]},{"id":"8c1ae8b0.fc9488","type":"mqtt out","z":"d664133d.f572c","name":"","topic":"nodered/motion2","qos":"","retain":"","broker":"987c4047.b2d81","x":590,"y":340,"wires":[]},{"id":"aac420af.2c7df","type":"function","z":"d664133d.f572c","name":"","func":"if (msg.payload ==\"ON\") {\n msg.reset = true;\n msg.payload = \"ON\"\n}\nelse{\n \n msg.payload = \"ON\"\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":320,"wires":[["8c1ae8b0.fc9488","69e6eee8.548e2","9b992535.2929c8"]]},{"id":"1becfca.4d5af03","type":"mqtt out","z":"d664133d.f572c","name":"","topic":"nodered/motion2","qos":"","retain":"","broker":"987c4047.b2d81","x":590,"y":520,"wires":[]},{"id":"792b35c4.6d4e7c","type":"function","z":"d664133d.f572c","name":"","func":"if (msg.payload ==\"ON\") {\n msg.payload = \"OFF\"\n}\nelse{\n msg.payload = \"OFF\"\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":460,"wires":[["1becfca.4d5af03","69e6eee8.548e2"]]},{"id":"987c4047.b2d81","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]
Now the HA automation
binarysensor
- platform: mqtt
name: "MAME Motion"
state_topic: "nodered/motion2"
qos: 2
retain: true
payload_on: "ON"
payload_off: "OFF"
Switch
- platform: mqtt
entity_id: mamescreen
name: "Mame Screen"
state_topic: "stat/MAME/POWER1"
command_topic: "cmnd/MAME/POWER1"
payload_on: "ON"
payload_off: "OFF"
optimistic: false
qos: 0
- id: '1530486159608'
alias: Mame Screen ON
trigger:
- entity_id: binary_sensor.mame_motion
platform: state
to: 'on'
condition: []
action:
- data:
entity_id: switch.mame_screen
service: switch.turn_on
- id: '1530486245034'
alias: Mame Screen OFF
trigger:
- entity_id: binary_sensor.mame_motion
platform: state
to: 'off'
condition: []
action:
- data:
entity_id: switch.mame_screen
service: switch.turn_off
walk upto MAME box and the Screen comes on stay on until I walk away after about 2mins ±
hope this help someone