Home Gamification

Tema

Home Gamification - para miúdos e graúdos

Resumo

Gamification não é algo novo e apareceu para tornar as tarefas do dia a dia um “jogo”. O maior foco é mais a nível profissional para motivar os colaboradores das empresas a atingir ou superar objetivos, mas também existem outras aplicações como por exemplo acumular pontos e receber prémios através da realização de ações sociais, amigas do ambiente, etc…
A ideia de trazer isto para o ambiente de domestico foi por carolice, para aprender e explorar novas áreas. No exemplo que vou expor aqui trata-se da gamificação orientada a atividades do dia a dia para duas crianças mas a imaginação é o limite e claro que se pode aplicar a casais sem filhos (mas com outras regras) ou mesmo vivendo sozinho :slight_smile: … se atingires X pontos podes comprar mais um google Mini :smiley:

Descrição

Para efetuar este projeto optei por usar tags RFID maioritariamente porque nunca tinha usado e queria experimentar, mas também porque acho mais interativo e didático tendo em conta que no meu caso foi para ser dirigido a crianças (cada um vai ter as suas tags e quando completar uma ação vai lá passar a tag correspondente… se fizerem batota são logo apanhados :slight_smile: e penalização para cima :smiley: . No futuro quando deixar de fazer sentido posso fazer o repurpose dos RFIDs para outro uso como ativar scenes, tocar determinadas músicas, fazer jogos, etc…

Optei neste caso por ter pontos por ações positivas e penalizações por ações negativas mas isto serve apenas de exemplo e deve ser adaptado a realidade de cada um. Cada ação pode ter pontuação distinta e não deixo usar a mesma tag mais que uma vez num intrevalo inferior a 30 min. Optei por criar as regras do jogo no Node-Red mas no limite podia ser algo muito mais simples com counters e automations diretas no HA.
Não tive grande tempo para afinar a coisa e existem algumas otimizações de código que podiam ser feitas mas penso que é uma base bastante boa.

FOTOS

  1. Esquema:
  2. Esquema caixa

    (Se quiserem os STLs digam mas não esta nada muito elaborado até porque isto é um protótipo e não queria soldar nada. Acho que fica bem melhor e mais compacto se soldarem tudo numa placa)
  3. Na caixa



  4. Tags
  5. Idenfificação das tags via HA
    Para identificar as tags usei a funcionalidade de tags do HA… basta ir a Configuration->Tags. No meu caso foi só para saber os tag-ids para configurar os flows no NodeRed mas para versões mais simples como a que disse em cima pode-se criar a automação directamente desta página.
  6. Dashboard
    (os graficos não fazem muito sentido porque ainda não são dados reais e andei a apagar varias vezes para testar)

CÓDIGO

esphome:
  name: rfid_reader
  platform: ESP8266
  board: d1_mini

# Buzzer notification after api connection success
  on_boot:
    priority: -10
    then:
    - wait_until:
        api.connected:
    - rtttl.play: "success:d=24,o=5,b=100:c,g,b"
   
# Wifi detail and static ip configuration
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
  manual_ip:
    static_ip: !secret rfid_reader_ip
    gateway: !secret wifi_gateway
    subnet: !secret wifi_subnet
  
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "rfid_reader Hotspot"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  services:
# Allows to play ok notification sound on the buzzer from HA
  - service: rfidreader_tag_ok
    then:
    - rtttl.play: "ok:d=24,o=5,b=100:c4,g4,b4"

# Allows to play ko notification sound on the buzzer from HA
  - service: rfidreader_tag_ko
    then:
    - rtttl.play: "ko:d=24,o=5,b=100:28a4,6d4"

# Allows to play any sound/song you wish on the buzzer from HA
  - service: play_rtttl
    variables:
      song_str: string
    then:
    - rtttl.play: !lambda 'return song_str;'
    
switch:
# creates a switch in HA that can be used to control whether the ok sounds plays by default "on tag"
- platform: template
  name: "rfid Buzzer Enabled"
  id: buzzer_enabled
  icon: mdi:volume-high
  optimistic: true
  restore_state: true
  
ota:

#RC522 runs on SPI so this block is to configure where the PINs are connected to the D1 mini
spi:
  clk_pin: D5
  miso_pin: D6
  mosi_pin: D7

rc522_spi: 
  cs_pin: D8
  update_interval: 1s

#logic of what happens when a tag is detected. In this case it calls tha tag scanned feature in HA  
  on_tag:
    then:
    - homeassistant.tag_scanned: !lambda 'return x;'
    - if:
        condition:
          switch.is_on: buzzer_enabled
        then:
        - rtttl.play: "ok:d=24,o=5,b=100:c4,g4,b4"      

# Configuration to allow the buzzer to be used as output for RTTTL
output:
  - platform: esp8266_pwm
    pin: D0
    id: buzzer

rtttl:
  output: buzzer
  • HA
################################################################################
# TYPE: Package
# FILENAME: package_gamification.yaml
# NAME: Home Gamification Challenge
################################################################################

utility_meter:
  gamification_pedro_monthly:
    source: sensor.gamification_pedro_counter
    cycle: monthly
  gamification_pedro_weekly:
    source: sensor.gamification_pedro_counter
    cycle: weekly
  gamification_pedro_daily:
    source: sensor.gamification_pedro_counter
    cycle: daily
  gamification_pedro_monthly_penalties:
    source: sensor.gamification_pedro_penalties_counter
    cycle: monthly
  gamification_pedro_weekly_penalties:
    source: sensor.gamification_pedro_penalties_counter
    cycle: weekly
  gamification_pedro_daily_penalties:
    source: sensor.gamification_pedro_penalties_counter
    cycle: daily
  gamification_andre_monthly:
    source: sensor.gamification_andre_counter
    cycle: monthly
  gamification_andre_weekly:
    source: sensor.gamification_andre_counter
    cycle: weekly
  gamification_andre_daily:
    source: sensor.gamification_andre_counter
    cycle: daily
  gamification_andre_monthly_penalties:
    source: sensor.gamification_andre_penalties_counter
    cycle: monthly
  gamification_andre_weekly_penalties:
    source: sensor.gamification_andre_penalties_counter
    cycle: weekly
  gamification_andre_daily_penalties:
    source: sensor.gamification_andre_penalties_counter
    cycle: daily

################################################################################
#### SCRIPTS
################################################################################

script:
  gamification_reset_pedro:
    sequence:
      - service: mqtt.publish
        data_template:
          payload: 0
          retain: true
          topic: gamification/Pedro
      - service: mqtt.publish
        data_template:
          payload: 0
          retain: true
          topic: gamification/Pedro/penalties
  gamification_reset_andre:
    sequence:
      - service: mqtt.publish
        data_template:
          payload: 0
          retain: true
          topic: gamification/Andre
      - service: mqtt.publish
        data_template:
          payload: 0
          retain: true
          topic: gamification/Andre/penalties

  ###temporary to facilitate testing
  gamification_reset_utility_meters_pedro:
    sequence:
      - service: utility_meter.calibrate
        data_template:
          entity_id: sensor.gamification_pedro_monthly, sensor.gamification_pedro_weekly, sensor.gamification_pedro_daily, sensor.gamification_pedro_monthly_penalties, sensor.gamification_pedro_weekly_penalties, sensor.gamification_pedro_daily_penalties
          value: 0
  gamification_reset_utility_meters_andre:
    sequence:
      - service: utility_meter.calibrate
        data_template:
          entity_id: sensor.gamification_andre_monthly, sensor.gamification_andre_weekly, sensor.gamification_andre_daily, sensor.gamification_andre_monthly_penalties, sensor.gamification_andre_weekly_penalties, sensor.gamification_andre_daily_penalties
          value: 0

################################################################################
#### INPUT NUMBER
################################################################################

input_number:
  gamification_task_1_points:
    name: "Fazer cama e arrumar roupa"
    min: 0
    max: 10
    initial: 2
    icon: mdi:alpha-p-circle
  gamification_task_2_points:
    name: "Pôr ou levantar a mesa"
    min: 0
    max: 10
    initial: 2
    icon: mdi:alpha-p-circle
  gamification_task_3_points:
    name: "Lavar as mãos"
    min: 0
    max: 10
    initial: 1
    icon: mdi:alpha-p-circle
  gamification_task_4_points:
    name: "Lavar os dentes"
    min: 0
    max: 10
    initial: 1
    icon: mdi:alpha-p-circle
  gamification_penalty_points:
    name: "penalização"
    min: 0
    max: 10
    initial: 1
    icon: mdi:alpha-p-circle

################################################################################
#### SENSORS
################################################################################

sensor:
  - platform: mqtt
    name: Gamification Pedro counter
    state_topic: "gamification/Pedro"
    force_update: true
    unit_of_measurement: "points"
  - platform: mqtt
    name: Gamification Pedro penalties counter
    state_topic: "gamification/Pedro/penalties"
    force_update: true
    unit_of_measurement: "points"
  - platform: mqtt
    name: Gamification Andre counter
    state_topic: "gamification/Andre"
    force_update: true
    unit_of_measurement: "points"
  - platform: mqtt
    name: Gamification Andre penalties counter
    state_topic: "gamification/Andre/penalties"
    force_update: true
    unit_of_measurement: "points"

  ################################################################################
  #### SENSOR TEMPLATES
  ################################################################################

  - platform: template
    sensors:
      gamification_pedro_total:
        value_template: "{{ states('sensor.gamification_pedro_counter') | int - states('sensor.gamification_pedro_penalties_counter') | int }}"
        unit_of_measurement: points
      gamification_pedro_daily_total:
        value_template: "{{ states('sensor.gamification_pedro_daily') | int - states('sensor.gamification_pedro_daily_penalties') | int }}"
        unit_of_measurement: points
      gamification_pedro_weekly_total:
        value_template: "{{ states('sensor.gamification_pedro_weekly') | int - states('sensor.gamification_pedro_weekly_penalties') | int }}"
        unit_of_measurement: points
      gamification_pedro_monthly_total:
        value_template: "{{ states('sensor.gamification_pedro_monthly') | int - states('sensor.gamification_pedro_monthly_penalties') | int }}"
        unit_of_measurement: points
      gamification_andre_total:
        value_template: "{{ states('sensor.gamification_andre_counter') | int - states('sensor.gamification_andre_penalties_counter') | int}}"
        unit_of_measurement: points
      gamification_andre_daily_total:
        value_template: "{{ states('sensor.gamification_andre_daily') | int - states('sensor.gamification_andre_daily_penalties') | int}}"
        unit_of_measurement: points
      gamification_andre_weekly_total:
        value_template: "{{ states('sensor.gamification_andre_weekly') | int - states('sensor.gamification_andre_weekly_penalties') | int}}"
        unit_of_measurement: points
      gamification_andre_monthly_total:
        value_template: "{{ states('sensor.gamification_andre_monthly') | int - states('sensor.gamification_andre_monthly_penalties') | int}}"
        unit_of_measurement: points

####  ####  ####  ####
[{"id":"47c91f3f.a54b1","type":"tab","label":"Gamification","disabled":false,"info":""},{"id":"fcb26c0d.5a198","type":"server-events","z":"47c91f3f.a54b1","name":"","server":"f9fa03e6.57d07","event_type":"tag_scanned","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"x":130,"y":840,"wires":[["ac63e787.96b308","77c5b890.a575e8"]]},{"id":"ac63e787.96b308","type":"switch","z":"47c91f3f.a54b1","name":"Pedro","property":"payload.event.tag_id","propertyType":"msg","rules":[{"t":"eq","v":"C7-38-27-72","vt":"str"},{"t":"eq","v":"19-28-49-CA","vt":"str"},{"t":"eq","v":"87-9A-4B-73","vt":"str"},{"t":"eq","v":"D9-DE-69-CA","vt":"str"},{"t":"eq","v":"19-E7-76-CA","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":330,"y":480,"wires":[["f361a75c.c87e48"],["67630f5a.1116"],["b0357639.160b18"],["c80d1016.9e84a"],["31e8149b.5e465c"]]},{"id":"ac070dde.e436e","type":"mqtt out","z":"47c91f3f.a54b1","name":"Pedro counter","topic":"gamification/Pedro","qos":"1","retain":"true","broker":"19d036d4.c40939","x":1620,"y":420,"wires":[]},{"id":"3e77dd1e.2191b2","type":"change","z":"47c91f3f.a54b1","name":"Set counter","rules":[{"t":"set","p":"topic","pt":"msg","to":"counter","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":80,"wires":[["19782cf9.7e0183"]]},{"id":"253c7b41.a1ae34","type":"api-current-state","z":"47c91f3f.a54b1","name":"Current Pedro counter","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.gamification_pedro_counter","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":920,"y":80,"wires":[["3e77dd1e.2191b2"]]},{"id":"9d9fd79c.9197f8","type":"api-current-state","z":"47c91f3f.a54b1","name":"get task 1 points","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.gamification_task_1_points","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":900,"y":180,"wires":[["f39ec235.1b319"]]},{"id":"d7389b63.718628","type":"api-current-state","z":"47c91f3f.a54b1","name":"get task 2 points","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.gamification_task_2_points","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":900,"y":320,"wires":[["f39ec235.1b319"]]},{"id":"f39ec235.1b319","type":"change","z":"47c91f3f.a54b1","name":"Set points","rules":[{"t":"set","p":"topic","pt":"msg","to":"points","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1140,"y":420,"wires":[["19782cf9.7e0183"]]},{"id":"31e8149b.5e465c","type":"api-current-state","z":"47c91f3f.a54b1","name":"get penalty","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.gamification_penalty_points","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":530,"y":720,"wires":[["f26c265e.52f838","f3024452.743ba8"]]},{"id":"966da656.afaf48","type":"api-current-state","z":"47c91f3f.a54b1","name":"get task 3 points","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.gamification_task_3_points","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":900,"y":460,"wires":[["f39ec235.1b319"]]},{"id":"37cd8627.ee484a","type":"api-current-state","z":"47c91f3f.a54b1","name":"get task 4 points","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.gamification_task_4_points","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":900,"y":600,"wires":[["f39ec235.1b319"]]},{"id":"328fe334.b16fbc","type":"api-call-service","z":"47c91f3f.a54b1","name":"OK Sound","server":"f9fa03e6.57d07","version":1,"debugenabled":false,"service_domain":"esphome","service":"rfid_reader_rfidreader_tag_ok","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1610,"y":560,"wires":[[]]},{"id":"f361a75c.c87e48","type":"switch","z":"47c91f3f.a54b1","name":"","property":"banTask1P","propertyType":"flow","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":200,"wires":[["c30c31e8.d6612"],["ccfa50e5.ca6e5"]]},{"id":"c30c31e8.d6612","type":"change","z":"47c91f3f.a54b1","name":"ban task 1 On","rules":[{"t":"set","p":"banTask1P","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":180,"wires":[["9d9fd79c.9197f8","14516b8d.c52244","253c7b41.a1ae34"]]},{"id":"ccfa50e5.ca6e5","type":"api-call-service","z":"47c91f3f.a54b1","name":"KO sound","server":"f9fa03e6.57d07","version":1,"debugenabled":false,"service_domain":"esphome","service":"rfid_reader_rfidreader_tag_ko","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":640,"y":220,"wires":[[]]},{"id":"57fb8b11.5201f4","type":"change","z":"47c91f3f.a54b1","name":"ban task 1 off","rules":[{"t":"set","p":"banTask1P","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":260,"wires":[[]]},{"id":"14516b8d.c52244","type":"delay","z":"47c91f3f.a54b1","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":890,"y":220,"wires":[["57fb8b11.5201f4"]]},{"id":"67630f5a.1116","type":"switch","z":"47c91f3f.a54b1","name":"","property":"banTask2P","propertyType":"flow","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":340,"wires":[["be920f32.895ec"],["8157c6b1.cbfc48"]]},{"id":"be920f32.895ec","type":"change","z":"47c91f3f.a54b1","name":"ban task 2 On","rules":[{"t":"set","p":"banTask2P","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":320,"wires":[["1e8005dd.4c2f5a","d7389b63.718628","253c7b41.a1ae34"]]},{"id":"8157c6b1.cbfc48","type":"api-call-service","z":"47c91f3f.a54b1","name":"KO sound","server":"f9fa03e6.57d07","version":1,"debugenabled":false,"service_domain":"esphome","service":"rfid_reader_rfidreader_tag_ko","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":640,"y":360,"wires":[[]]},{"id":"71e2ec9c.dc92c4","type":"change","z":"47c91f3f.a54b1","name":"ban task 2 off","rules":[{"t":"set","p":"banTask2P","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":400,"wires":[[]]},{"id":"1e8005dd.4c2f5a","type":"delay","z":"47c91f3f.a54b1","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":890,"y":360,"wires":[["71e2ec9c.dc92c4"]]},{"id":"49cafb7d.70d094","type":"function","z":"47c91f3f.a54b1","name":"Initiate flow Vars","func":"flow.set('banTask1P',false);\nflow.set('banTask2P',false);\nflow.set('banTask3P',false);\nflow.set('banTask4P',false);\n\nflow.set('banTask1A',false);\nflow.set('banTask2A',false);\nflow.set('banTask3A',false);\nflow.set('banTask4A',false);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":140,"y":760,"wires":[[]]},{"id":"7a707460.39cbfc","type":"inject","z":"47c91f3f.a54b1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":700,"wires":[["49cafb7d.70d094"]]},{"id":"b0357639.160b18","type":"switch","z":"47c91f3f.a54b1","name":"","property":"banTask3P","propertyType":"flow","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":480,"wires":[["3847988b.6a4358"],["7e459dec.f02934"]]},{"id":"3847988b.6a4358","type":"change","z":"47c91f3f.a54b1","name":"ban task 3 On","rules":[{"t":"set","p":"banTask3P","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":460,"wires":[["7f02ef49.9aca2","966da656.afaf48","253c7b41.a1ae34"]]},{"id":"7e459dec.f02934","type":"api-call-service","z":"47c91f3f.a54b1","name":"KO sound","server":"f9fa03e6.57d07","version":1,"debugenabled":false,"service_domain":"esphome","service":"rfid_reader_rfidreader_tag_ko","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":640,"y":500,"wires":[[]]},{"id":"a5cbf9c7.edf378","type":"change","z":"47c91f3f.a54b1","name":"ban task 3 off","rules":[{"t":"set","p":"banTask3P","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":540,"wires":[[]]},{"id":"7f02ef49.9aca2","type":"delay","z":"47c91f3f.a54b1","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":890,"y":500,"wires":[["a5cbf9c7.edf378"]]},{"id":"c80d1016.9e84a","type":"switch","z":"47c91f3f.a54b1","name":"","property":"banTask4P","propertyType":"flow","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":620,"wires":[["1b1af652.000dda"],["453a3f2d.16278"]]},{"id":"1b1af652.000dda","type":"change","z":"47c91f3f.a54b1","name":"ban task 4 On","rules":[{"t":"set","p":"banTask4P","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":600,"wires":[["5ae6228a.1d2afc","37cd8627.ee484a","253c7b41.a1ae34"]]},{"id":"453a3f2d.16278","type":"api-call-service","z":"47c91f3f.a54b1","name":"KO sound","server":"f9fa03e6.57d07","version":1,"debugenabled":false,"service_domain":"esphome","service":"rfid_reader_rfidreader_tag_ko","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":640,"y":640,"wires":[[]]},{"id":"5b601a0b.2698c4","type":"change","z":"47c91f3f.a54b1","name":"ban task 4 off","rules":[{"t":"set","p":"banTask4P","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":680,"wires":[[]]},{"id":"5ae6228a.1d2afc","type":"delay","z":"47c91f3f.a54b1","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":890,"y":640,"wires":[["5b601a0b.2698c4"]]},{"id":"77c5b890.a575e8","type":"switch","z":"47c91f3f.a54b1","name":"André","property":"payload.event.tag_id","propertyType":"msg","rules":[{"t":"eq","v":"19-5C-4D-CA","vt":"str"},{"t":"eq","v":"17-73-25-72","vt":"str"},{"t":"eq","v":"69-BD-49-CA","vt":"str"},{"t":"eq","v":"D9-3F-72-CA","vt":"str"},{"t":"eq","v":"39-04-6E-CA","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":330,"y":1240,"wires":[["4ca99fc4.029c5"],["4e7c99ae.949198"],["8befe6c.e1df118"],["1d939411.8f467c"],["8c1ca8c.5990858"]]},{"id":"8de9842f.95dbd8","type":"mqtt out","z":"47c91f3f.a54b1","name":"André counter","topic":"gamification/Andre","qos":"1","retain":"true","broker":"19d036d4.c40939","x":1640,"y":1180,"wires":[]},{"id":"4f330885.779a98","type":"api-current-state","z":"47c91f3f.a54b1","name":"Current André counter","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.gamification_andre_counter","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":920,"y":840,"wires":[["66669821.1b4178"]]},{"id":"acaa40c6.94dc8","type":"api-current-state","z":"47c91f3f.a54b1","name":"get task 1 points","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.gamification_task_1_points","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":900,"y":940,"wires":[["ba566780.47fbe8"]]},{"id":"40bfbd47.0c4a04","type":"api-current-state","z":"47c91f3f.a54b1","name":"get task 2 points","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.gamification_task_2_points","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":900,"y":1080,"wires":[["ba566780.47fbe8"]]},{"id":"8c1ca8c.5990858","type":"api-current-state","z":"47c91f3f.a54b1","name":"get penalty","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.gamification_penalty_points","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":530,"y":1480,"wires":[["ae6c1812.306778","65bcfcb4.f4a0d4"]]},{"id":"44a35619.e3f1d8","type":"api-current-state","z":"47c91f3f.a54b1","name":"get task 3 points","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.gamification_task_3_points","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":900,"y":1220,"wires":[["ba566780.47fbe8"]]},{"id":"7b47ae5b.99256","type":"api-current-state","z":"47c91f3f.a54b1","name":"get task 4 points","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.gamification_task_4_points","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":900,"y":1360,"wires":[["ba566780.47fbe8"]]},{"id":"4ca99fc4.029c5","type":"switch","z":"47c91f3f.a54b1","name":"","property":"banTask1A","propertyType":"flow","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":960,"wires":[["fbf1f8c2.27ed68"],["a725aa21.5407b8"]]},{"id":"fbf1f8c2.27ed68","type":"change","z":"47c91f3f.a54b1","name":"ban task 1 On","rules":[{"t":"set","p":"banTask1A","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":940,"wires":[["acaa40c6.94dc8","92090a7f.bf5338","4f330885.779a98"]]},{"id":"a725aa21.5407b8","type":"api-call-service","z":"47c91f3f.a54b1","name":"KO sound","server":"f9fa03e6.57d07","version":1,"debugenabled":false,"service_domain":"esphome","service":"rfid_reader_rfidreader_tag_ko","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":640,"y":980,"wires":[[]]},{"id":"a8458ad.95c3b78","type":"change","z":"47c91f3f.a54b1","name":"ban task 1 off","rules":[{"t":"set","p":"banTask1A","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":1020,"wires":[[]]},{"id":"92090a7f.bf5338","type":"delay","z":"47c91f3f.a54b1","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":890,"y":980,"wires":[["a8458ad.95c3b78"]]},{"id":"4e7c99ae.949198","type":"switch","z":"47c91f3f.a54b1","name":"","property":"banTask2A","propertyType":"flow","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":1100,"wires":[["5f803908.8c09b8"],["27dafc6d.24cd54"]]},{"id":"5f803908.8c09b8","type":"change","z":"47c91f3f.a54b1","name":"ban task 2 On","rules":[{"t":"set","p":"banTask2A","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":1080,"wires":[["a8000a35.7a15c8","40bfbd47.0c4a04","4f330885.779a98"]]},{"id":"27dafc6d.24cd54","type":"api-call-service","z":"47c91f3f.a54b1","name":"KO sound","server":"f9fa03e6.57d07","version":1,"debugenabled":false,"service_domain":"esphome","service":"rfid_reader_rfidreader_tag_ko","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":640,"y":1120,"wires":[[]]},{"id":"954ba5da.8d6d78","type":"change","z":"47c91f3f.a54b1","name":"ban task 2 off","rules":[{"t":"set","p":"banTask2A","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":1160,"wires":[[]]},{"id":"a8000a35.7a15c8","type":"delay","z":"47c91f3f.a54b1","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":890,"y":1120,"wires":[["954ba5da.8d6d78"]]},{"id":"8befe6c.e1df118","type":"switch","z":"47c91f3f.a54b1","name":"","property":"banTask3A","propertyType":"flow","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":1240,"wires":[["c3aa3ec6.658b4"],["a4e972e0.56c62"]]},{"id":"c3aa3ec6.658b4","type":"change","z":"47c91f3f.a54b1","name":"ban task 3 On","rules":[{"t":"set","p":"banTask3A","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":1220,"wires":[["3bbd4b63.1dcb84","44a35619.e3f1d8","4f330885.779a98"]]},{"id":"a4e972e0.56c62","type":"api-call-service","z":"47c91f3f.a54b1","name":"KO sound","server":"f9fa03e6.57d07","version":1,"debugenabled":false,"service_domain":"esphome","service":"rfid_reader_rfidreader_tag_ko","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":640,"y":1260,"wires":[[]]},{"id":"2e78b893.491548","type":"change","z":"47c91f3f.a54b1","name":"ban task 3 off","rules":[{"t":"set","p":"banTask3A","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":1300,"wires":[[]]},{"id":"3bbd4b63.1dcb84","type":"delay","z":"47c91f3f.a54b1","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":890,"y":1260,"wires":[["2e78b893.491548"]]},{"id":"1d939411.8f467c","type":"switch","z":"47c91f3f.a54b1","name":"","property":"banTask4A","propertyType":"flow","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":1380,"wires":[["b8a18f3d.65e52"],["e5deb081.f4138"]]},{"id":"b8a18f3d.65e52","type":"change","z":"47c91f3f.a54b1","name":"ban task 4 On","rules":[{"t":"set","p":"banTask4A","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":1360,"wires":[["b3a655f6.e03f38","7b47ae5b.99256","4f330885.779a98"]]},{"id":"e5deb081.f4138","type":"api-call-service","z":"47c91f3f.a54b1","name":"KO sound","server":"f9fa03e6.57d07","version":1,"debugenabled":false,"service_domain":"esphome","service":"rfid_reader_rfidreader_tag_ko","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":640,"y":1400,"wires":[[]]},{"id":"ad3133e0.ef148","type":"change","z":"47c91f3f.a54b1","name":"ban task 4 off","rules":[{"t":"set","p":"banTask4A","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":1440,"wires":[[]]},{"id":"b3a655f6.e03f38","type":"delay","z":"47c91f3f.a54b1","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":890,"y":1400,"wires":[["ad3133e0.ef148"]]},{"id":"19782cf9.7e0183","type":"join","z":"47c91f3f.a54b1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1310,"y":420,"wires":[["6ae2d17e.030db"]]},{"id":"6ae2d17e.030db","type":"function","z":"47c91f3f.a54b1","name":"sum","func":"msg.payload = msg.payload.counter + msg.payload.points\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1450,"y":420,"wires":[["ac070dde.e436e","328fe334.b16fbc"]]},{"id":"f26c265e.52f838","type":"api-current-state","z":"47c91f3f.a54b1","name":"Current Pedro penalties counter","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.gamification_pedro_penalties_counter","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":810,"y":780,"wires":[["51acfa4a.57a7e4"]]},{"id":"51acfa4a.57a7e4","type":"change","z":"47c91f3f.a54b1","name":"Set penalty counter","rules":[{"t":"set","p":"topic","pt":"msg","to":"penalty_counter","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":780,"wires":[["111206b.330cbf9"]]},{"id":"f3024452.743ba8","type":"change","z":"47c91f3f.a54b1","name":"Set penalty points","rules":[{"t":"set","p":"topic","pt":"msg","to":"penalty_points","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":720,"wires":[["111206b.330cbf9"]]},{"id":"111206b.330cbf9","type":"join","z":"47c91f3f.a54b1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1310,"y":740,"wires":[["5915e556.b4dadc"]]},{"id":"5915e556.b4dadc","type":"function","z":"47c91f3f.a54b1","name":"sum","func":"msg.payload = msg.payload.penalty_counter + msg.payload.penalty_points\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1450,"y":740,"wires":[["328fe334.b16fbc","9e53aa4c.cab928"]]},{"id":"9e53aa4c.cab928","type":"mqtt out","z":"47c91f3f.a54b1","name":"Pedro penalty counter","topic":"gamification/Pedro/penalties","qos":"1","retain":"true","broker":"19d036d4.c40939","x":1640,"y":740,"wires":[]},{"id":"66669821.1b4178","type":"change","z":"47c91f3f.a54b1","name":"Set counter","rules":[{"t":"set","p":"topic","pt":"msg","to":"counter","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":840,"wires":[["41120d9e.42be44"]]},{"id":"ba566780.47fbe8","type":"change","z":"47c91f3f.a54b1","name":"Set points","rules":[{"t":"set","p":"topic","pt":"msg","to":"points","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1160,"y":1180,"wires":[["41120d9e.42be44"]]},{"id":"3585c5d4.3522ba","type":"api-call-service","z":"47c91f3f.a54b1","name":"OK Sound","server":"f9fa03e6.57d07","version":1,"debugenabled":false,"service_domain":"esphome","service":"rfid_reader_rfidreader_tag_ok","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1630,"y":1320,"wires":[[]]},{"id":"41120d9e.42be44","type":"join","z":"47c91f3f.a54b1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1330,"y":1180,"wires":[["eeb2fd91.5578a"]]},{"id":"eeb2fd91.5578a","type":"function","z":"47c91f3f.a54b1","name":"sum","func":"msg.payload = msg.payload.counter + msg.payload.points\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1470,"y":1180,"wires":[["3585c5d4.3522ba","8de9842f.95dbd8"]]},{"id":"65bcfcb4.f4a0d4","type":"api-current-state","z":"47c91f3f.a54b1","name":"Current André penalties counter","server":"f9fa03e6.57d07","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.gamification_andre_penalties_counter","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":830,"y":1540,"wires":[["c33fde1c.bb558"]]},{"id":"c33fde1c.bb558","type":"change","z":"47c91f3f.a54b1","name":"Set penalty counter","rules":[{"t":"set","p":"topic","pt":"msg","to":"penalty_counter","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":1540,"wires":[["ecb93303.e8cde"]]},{"id":"ae6c1812.306778","type":"change","z":"47c91f3f.a54b1","name":"Set penalty points","rules":[{"t":"set","p":"topic","pt":"msg","to":"penalty_points","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":1480,"wires":[["ecb93303.e8cde"]]},{"id":"ecb93303.e8cde","type":"join","z":"47c91f3f.a54b1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1330,"y":1500,"wires":[["5729690.49c6f98"]]},{"id":"5729690.49c6f98","type":"function","z":"47c91f3f.a54b1","name":"sum","func":"msg.payload = msg.payload.penalty_counter + msg.payload.penalty_points\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1470,"y":1500,"wires":[["908146f3.04ade8","3585c5d4.3522ba"]]},{"id":"908146f3.04ade8","type":"mqtt out","z":"47c91f3f.a54b1","name":"André penalty counter","topic":"gamification/Andre/penalties","qos":"1","retain":"true","broker":"19d036d4.c40939","x":1660,"y":1500,"wires":[]},{"id":"f9fa03e6.57d07","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"19d036d4.c40939","type":"mqtt-broker","name":"mosquitto","broker":"192.168.1.90","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Lista de Material

  • 1 RFID.RC522 reader (caso queiram também podem usar um NFC reader PN532… terão é de alterar o código ou seguir o link no qual me basiei
  • XX RFID tags (a quantidade depende do que querem realmente fazer)
  • 1 Wemos D1 Mini ( ou outro controlador qualquer)
  • 1 buzzer (opcional)
  • 1 Carregador e cabo respetivo cabo USB para alimentar o wemos (ou outra fonte caso queiram alimentar o controlador diretamente)
  • jumper wires

Copyright © 2017-2021. Todos os direitos reservados
CPHA.pt - info@cpha.pt


FAQ | Termos de Serviço/Regras | Política de Privacidade