Trigger Gladys ambiance scenes with NFC cards

Hello,

I’m thinking about a small interactive project using physical cards equipped with NFC tags to trigger different moods in Gladys.

The idea would be to place a very thin NFC tag in the pocket of each card. When the card is scanned with a phone, it sends an identifier to Gladys via HTTP or MQTT.

Gladys could then:

  • change the color and brightness of the lights

  • play a music or local sound ambiance

  • activate a scene for a set duration

  • record the last scanned card

  • display its name on the dashboard

  • automatically return to the normal ambiance after a few minutes

The project would contain 78 different cards. Here is the list I would use to associate each NFC identifier with a name and a mood:

I specify that I participate in the maintenance of the linked site. I share this page solely to show the dataset and the 78 entries that the automation should handle.

I am now looking for the best architecture in Gladys.

1. HTTP or MQTT to transmit the identifier?

For mainly local use, is it better for the phone to publish the card identifier directly on an MQTT topic?

For example:

gladys/nfc/card

With a value like:

the-world

Or would it be simpler to use NFC Tools or Tasker to send an HTTP request to the Gladys API?

2. A virtual device to store the card

I thought of creating an MQTT virtual device with a text or numeric feature representing the last scanned card.

Is this a good method to allow scenes to react to the value, or should a different scene be triggered directly from the phone?

3. Avoid creating 78 scenes

I would prefer not to create a separate scene for each card.

Is there a clean way to create a single scene that:

  1. retrieves the received identifier

  2. looks up this identifier in a lookup table

  3. retrieves the associated color, brightness, sound, and duration

  4. executes the corresponding actions

The table could look like this:

{
  "the-world": {
    "color": "#D4AF37",
    "brightness": 45,
    "duration": 900
  },
  "the-hermit": {
    "color": "#6B7280",
    "brightness": 20,
    "duration": 1200
  }
}

Can this type of logic be handled directly in Gladys, or would it be better to go through Node-RED or a small external integration?

4. Detecting the card upright or reversed

A card can be placed normally or turned 180 degrees.

I could record two different NFC actions on the phone, for example:

the-world:upright
the-world:reversed

But this would probably require two tags per card.

Do you see a simpler method to also transmit the card’s orientation?

5. Timing and restoring the previous state

After 10 or 15 minutes, I would like to restore the lights and devices to their previous state.

Does Gladys allow saving the states before launching the scene, then automatically restoring them at the end?

Otherwise, I could simply launch a normal ambiance scene after a fixed delay.

6. Display on the dashboard

Finally, would it be possible to display in the dashboard:

  • the name of the last card

  • the scan time

  • its orientation

  • the currently active ambiance

I want to start with a prototype with only three cards before preparing the 78.

For this type of project, would you rather use MQTT, the Open API, Node-RED, or Gladys’s future external integrations system?

Hi @selamibaba, and welcome to Gladys :slight_smile:

Great project, I love the idea :slightly_smiling_face:

Good news: almost everything you describe is doable with Gladys today, without any code. I’ll go through your questions in order:

1. MQTT or HTTP? I’d recommend MQTT. Gladys can install its own broker (MQTT integration, in 1 click), and most importantly, scenes have a trigger „MQTT Message Received‟: you choose a topic (e.g. tarot/scan), and the message content is then accessible in the scene actions via the variable {{triggerEvent.message}}. With HTTP, you can only start a scene via the API (POST /api/v1/scene/:selector/start), but without passing it any parameters — so less flexible for your case.

2. Remember the last scanned card. Create a virtual device in the MQTT integration with a text-type feature. Your reader (or your scene) publishes to gladys/master/device/[id_device]/feature/[id_feature]/text and Gladys saves the value, with history. You can then display it on the dashboard with the „Devices‟ widget.

3. Avoid 78 scenes. Honestly, I wouldn’t put the lookup table in Gladys: there’s no (yet) notion of lookup table in scenes, and 78 „if/then‟ branches would be unmanageable. The cleanest solution is to put the card → parameters (color, brightness, duration) mapping as close to the reader as possible: either in the ESP firmware that reads the tags, or in Node-RED (there’s an official Node-RED integration in Gladys that installs it in 1 click). The reader/Node-RED then publishes a message already „resolved‟ (e.g. the color on one topic, the brightness on another, the card name on a third), and on the Gladys side, a single generic scene applies these values with {{triggerEvent.message}}. One entry to modify = one line in your table, not a scene to touch.

4. Card right side up / upside down. This isn’t something an NFC tag can indicate: the tag returns the same identifier regardless of its orientation. The classic solution is hardware-based: two tags per card (one at the top, one at the bottom) with a short-range antenna reader that only reads the closest tag. You then get two identifiers per card, and it’s your lookup table that translates „Moon ID #2 = Upside Down Moon‟. On the Gladys side, it’s transparent.

5. Restore lamp states after 15 min. Rather than putting a delay in the scan scene, use the „Device State Change‟ trigger with the option „Run the scene after the condition has been valid for X minutes‟: create a virtual feature „ambiance active‟, which your scan scene sets to 0 then to 1 with each card (the 0→1 re-arms the counter, so a new scan properly delays the restoration by 15 min). A second scene, triggered on „ambiance active = 1 for 15 minutes‟, restores the lighting to its normal state and sets the feature back to 0. If you want to restore the exact state before the scan (and not a default state), have the scan scene copy the lamp states to backup virtual features, which the restore scene will reapply.

6. Dashboard. The „Devices‟ widget will display your text features (card name, ambiance active), and there’s a clock widget for the time.

Don’t hesitate to share photos of the setup when it’s running, that would make a great topic to share with the community! :crystal_ball: