# ¶ TARIFF LED INDICATOR CONTROLLED BY COFYBOX

## ¶ Target

- Develop a device to be used as a visual light tariff indicator, helping users easily identify the optimal moments to use energy based on the Cozybox information.

## ¶ Components

- Board: Wemos D1 mini
- Led: RGB LED Shield WS2812B for Wemos D1 mini
- Micro USB cable for 5V power supply

## ¶ Steps

1. Solder the RGB LED Shield to the board

2. Install ESPHome into Home Assistant
3. Create a new device according to your board. In this example, uncheck 'use recommended settings' because we want one specific 'ESP8266' board

3. 1. Skip the rest

4. Then edit the device, setting the WiFi you want it to connect to, and add the code for the light device at the bottom. In this case, we used the code from NeoPixelBus.

4. 1. Click “Save” and next “Validate” to check the code

5. “Install” this code into the board, using one of the options available. In this example we used “Manual download” and “Legacy format” to install it with the tool ESPHome Flasher.

6. Once you have the board flashed with this code, normally it would be found by Home Assistant as a new device, and you can add it to the list of devices. If the device is not automatically detected, you can try integrating it by adding a new ESPhome device. You may need the name you used for the device to set up “host” (probably you may need to add “.local” to the name, as in the example below).

7. You can now use the device as a light device, using the relay to turn on/off the light and the color matrix to set the desired color.

8. Finally you could set automations to configure the color of the light depending on the tariff or surpluses you are having. This will serve as a visual signal to know the best moments to consume energy, specially in users with dynamic tariffs or self-consumption.

## ¶ Example of dynamic tariff

In the spanish case the price change hourly, as can be seen here:

The Cofycloud translates these 24 hours of pricing into a 5-level signal, as shown here. This -2 to +2 signal is sent to the Cofybox, and we need to represent this with light colors. For example, the ones below:

For this translation, follow the next steps:

1. Create an “input-select” helper with the categories you want:

> Note: in this case N/A [blinking white] is for moments where the signal is unavailable and not reaching the cofybox.

2. Create an automation to translate the cofycloud signal into one of these categories:

    alias: SOM_Cuca.matrix.translator
    description: ""
    trigger:
      - platform: state
        entity_id:
          - sensor.explicit_service_dhw
      - platform: time_pattern
        minutes: /15
    condition: []
    action:
      - choose:
          - conditions:
              - condition: or
                conditions:
                  - condition: state
                    entity_id: sensor.explicit_service_dhw
                    state: "-2.0"
                  - condition: state
                    entity_id: sensor.explicit_service_dhw
                    state: "-1.0"
                  - condition: state
                    entity_id: sensor.explicit_service_dhw
                    state: "-1"
                  - condition: state
                    entity_id: sensor.explicit_service_dhw
                    state: "-2"
            sequence:
              - service: input_select.select_option
                data:
                  option: Expensive [red]
                target:
                  entity_id: input_select.cuca_state
          - conditions:
              - condition: or
                conditions:
                  - condition: state
                    entity_id: sensor.explicit_service_dhw
                    state: "0.0"
                  - condition: state
                    entity_id: sensor.explicit_service_dhw
                    state: "0"
            sequence:
              - service: input_select.select_option
                data:
                  option: Medium [yellow]
                target:
                  entity_id: input_select.cuca_state
          - conditions:
              - condition: or
                conditions:
                  - condition: state
                    entity_id: sensor.explicit_service_dhw
                    state: "1"
                  - condition: state
                    entity_id: sensor.explicit_service_dhw
                    state: "1.0"
                  - condition: state
                    entity_id: sensor.explicit_service_dhw
                    state: "2"
                  - condition: state
                    entity_id: sensor.explicit_service_dhw
                    state: "2.0"
            sequence:
              - service: input_select.select_option
                data:
                  option: Cheap/Exporting [green]
                target:
                  entity_id: input_select.cuca_state
          - conditions:
              - condition: or
                conditions:
                  - condition: state
                    entity_id: sensor.explicit_service_dhw
                    state: unavailable
                  - condition: state
                    entity_id: sensor.explicit_service_dhw
                    state: unknown
            sequence:
              - service: input_select.select_option
                data:
                  option: N/A [blinking white]
                target:
                  entity_id: input_select.cuca_state
    mode: single

3. Finally, create an automation to translate the states of the “input.select” into action in the light device itself:

    alias: SOM_Cuca.control
    description: ""
    trigger:
      - platform: state
        entity_id:
          - input_select.cuca_state
      - platform: time_pattern
        minutes: /15
    condition: []
    action:
      - choose:
          - conditions:
              - condition: state
                entity_id: input_select.cuca_state
                state: Expensive [red]
            sequence:
              - service: light.turn_on
                data:
                  rgb_color:
                    - 255
                    - 0
                    - 0
                target:
                  entity_id: light.cuca_2leds_estrella_cuca_llum
          - conditions:
              - condition: state
                entity_id: input_select.cuca_state
                state: Medium [yellow]
            sequence:
              - service: light.turn_on
                data:
                  rgb_color:
                    - 255
                    - 210
                    - 0
                target:
                  entity_id: light.cuca_2leds_estrella_cuca_llum
          - conditions:
              - condition: state
                entity_id: input_select.cuca_state
                state: Cheap/Exporting [green]
            sequence:
              - service: light.turn_on
                data:
                  rgb_color:
                    - 0
                    - 255
                    - 0
                target:
                  entity_id: light.cuca_2leds_estrella_cuca_llum
              - service: light.turn_on
                data: {}
          - conditions:
              - condition: state
                entity_id: input_select.cuca_state
                state: N/A [blinking white]
            sequence:
              - repeat:
                  while:
                    - condition: state
                      entity_id: input_select.cuca_state
                      state: N/A [blinking white]
                  sequence:
                    - service: light.turn_on
                      data:
                        rgb_color:
                          - 255
                          - 255
                          - 255
                      target:
                        entity_id: light.cuca_2leds_estrella_cuca_llum
                    - delay:
                        hours: 0
                        minutes: 0
                        seconds: 1
                        milliseconds: 0
                    - service: light.turn_on
                      data:
                        rgb_color:
                          - 0
                          - 0
                          - 0
                      target:
                        entity_id: light.cuca_2leds_estrella_cuca_llum
                    - delay:
                        hours: 0
                        minutes: 0
                        seconds: 0
                        milliseconds: 600
    mode: queued

As a result, you will be able to see this translation in the historic tab, and below is an example of the prototype developed in this case:

## ¶