Displaying value from Shelly em on to lcd screen

I have a Shelly EM integrated with HA using the official Shelly integration. I can display the current power consumption in a dashboard using the entity id: 120a_power, however, I’d now like to display this value on a standalone lcd display…

Perhaps a picture might help:-

As you can see, I currently have the TTGO device displaying the output of the BME/BMP280, I’d like to modify the code so that the TTGO displays the Shelly Power and possibly the corresponding cost…

I just can’t get my head round the coding syntax…

You forgot to post the code you’d like to modify.

Ah, sorry, I don’t have any working code for showing the Shelly EM - I don’t know where to start with it. Having said that, I did try and work it out; I’m assuming I need a sensor, with platform: Shelly EM (?), I assume I need to name it and give it an id… I tried adding the following to the current yaml, but had to # it out in order to allow the TTGO to continue to work…

sensor:

#  - platform: Shelly_em
#  power:
#      name: "Power"
#      id: 120a_power

  - platform: bme280_i2c
    temperature:
      name: "BME280 Temperature"
      id: temperature
      filters:
        - offset: 0.25 # reduce temp by 2 deg C
      oversampling: 16x

Is your display running esphome? If so, you might want to update the category of this topic.

It is, I’ve redefined it as the ESPHome category.

Had some help on the ESPHome Facebook page - they pointed me to:

So, my code is:

number:
  - platform: homeassistant
    id: currentpower
    entity_id: sensor.120a_power

Nice that you resolved it! Next time don’t be shy with your yaml, just post it all.

No problem:

captive_portal:

number:
  - platform: homeassistant
    id: currentpower
    entity_id: sensor.120a_power

i2c:
  sda: 21
  scl: 22
  scan: True

# handle the two built-in push buttons:
binary_sensor:
  - platform: gpio
    name: 'Button Left'
    id: button_left
        
    pin:
      number: GPIO0
      inverted: True
      mode:
        input: True
        pullup: True

    filters: 
      - delayed_on: 10ms
      - delayed_off: 10ms

    # optional: this dims the display backlight:
    on_press:
      - light.dim_relative:
          id: back_light
          relative_brightness: 5%
          transition_length: 0.1s
          brightness_limits:
              min_brightness: 20%
      - delay: 0.1s

  - platform: gpio
    name: 'Button Right'
    id: button_right

    pin:
      number: GPIO35
      inverted: True
      mode:
        input: True

    filters: 
      - delayed_on: 10ms
      - delayed_off: 10ms

    # optional: this increases brightness of display backlight:
    on_press:
      - light.dim_relative:
          id: back_light
          relative_brightness: -5%
          transition_length: 0.1s
          brightness_limits:
            min_brightness: 20%
      - delay: 0.1s

# handle built-in display backlight:
# use a separate "light" component to enable dimming rather than
# using the "display" property for backlight gpio
output:
  - platform: ledc
    pin: 4
    id: display_backlight_pwm

light:
  - platform: monochromatic
    output: display_backlight_pwm
    name: "Display Backlight"
    id: back_light
    restore_mode: RESTORE_AND_ON
    effects:
      - pulse:
          name: noWifiConnection
          min_brightness: 60%
          max_brightness: 80%


sensor:

  - platform: bme280_i2c
    temperature:
      name: "BME280 Temperature"
      id: temperature
      filters:
        - offset: 0.25 # reduce temp by 2 deg C
      oversampling: 16x

    pressure:
      name: "BME280 Pressure"
      id: pressure
      filters:
        - offset: 8.5 # increase pressure by 10 hPa

    humidity:
      name: "BME280 Humidity"
      id: humidity
      filters:
       - offset: -10.4
    address: 0x76
    update_interval: 60s

font:
  - file: "fonts/Roboto-Medium.ttf"
    id: font_roboto
    size: 23
    glyphs: '!"%()+,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz/³µ'

color:
  - id: color_blue
    red: 0%
    green: 0%
    blue: 50%

  - id: color_red
    red: 50%
    green: 0%
    blue: 0%

  - id: color_green
    red: 0%
    green: 50%
    blue: 0%

  - id: color_white
    red: 50%
    green: 50%
    blue: 50%

time:
  - platform: homeassistant
    id: esptime

spi:
  clk_pin: GPIO18
  mosi_pin: GPIO19

display:
  - platform: st7789v
    model: TTGO TDisplay 135X240
    backlight_pin: no
    cs_pin: GPIO5
    dc_pin: GPIO16
    reset_pin: GPIO23
    rotation: 270

    lambda: |-
      it.printf((240 / 2), 20, id(font_roboto), id(color_red), TextAlign::CENTER, "Power: %.0f W", id(currentpower).state);
      it.printf((240 / 2), 65, id(font_roboto), id(color_green), TextAlign::CENTER, "Humidity: %.0f %%RH", id(humidity).state);
      it.printf((240 / 2), 110, id(font_roboto), id(color_blue), TextAlign::CENTER, "Pressure: %.0f hPa", id(pressure).state);    
      // Header
      it.rectangle(0,  0, it.get_width(), it.get_height(), id(color_blue));
      it.rectangle(0, 45, it.get_width(), it.get_height(), id(color_blue));
      it.rectangle(0, 90, it.get_width(), it.get_height(), id(color_blue));   
# °C
web_server:
  port: 80

The code originally displayed the output of the BMP280 on the display. There’s also coding that uses the built in buttons to increase or decrease the backlight brightness.

The modified code replaces the temperature readout with the current power value from the Shelly EM.