MQTT Switch to toggle a scene

Hi everyone,
Most of my devices are set up with HA now and I’m really diggin’ it.
One thing I’d like to realize is a simple “morning button”.
I’d like to have a button next to my bed that turns on my night stand lamp to a nice low light in the morning, or turns of all devices in the evening.
For the Button I’m using a Photon with the InternetButton Board (a little overkill but in the future I’d like to add some more functions).
The Photon is able to send MQTT messages.
So what’s the best way to implement the described functionality.

Button press
if lamp is off:
Turn on Scene/Lamp to nice warm light
or
if lamp is already on:
Turn off all devices

My main question is how do I set up a some MQTT topic, so that HA can receive a “toggle” command from the button and start the automation.

Thanks in advance.

Jan

You need some automations triggered by an MQTT message, sent by the Photon. The syntax is here

The conditions will be switches defined. There is a switch.toggle service, so you may not need to write separate automations for on and off, just call the toggle for the switch you want to change.

If it’s a simple case with just a lamp or group, then you can just use homeautomation.toggle, but if you have different cases like when the on action turns on lamp A and B, but the off action turns off A, B and C, then you will need two separate automations that uses the state platform with to: 'on' and to: 'off':

I would probably add one automation that toggles an input_boolean when you see the mqtt post, and have the two automations watch the state of that one, like this:

- alias: Test
  trigger:
    - platform: state
      entity_id: input_boolean.my_mqtt_switch
      to: 'on'
      # or
      to: 'off'
    ...