First time using template with power outlets and temperature sensor

Hi guys,

Trying this for 2 days now but can’t figure it out.

I got:

I’m using the mini-graph-card control to show the temperature, but I also want to see when the power outlet was on, in the same chart. It can be done, similar to what you see if you open the link, but I need a binary sensor (or sensor) for it.

How can I expose the switch.ikea-power-outlet entity also as a binary sensor so I can reference it in the mini-graph-card? I tried using the template integration but I can’t get it to work. I either get a binary sensor but it never gets updated accordingly to the state of the outlet, or I add a MQTT version but it’s not in the entity list.

Code snippets:

template:
    - binary_sensor:
      - name: "PWR_OUTLET_2_state"
        state: "{{ is_state('switch.pwr_outlet_2', 'On') }}"
######
binary_sensor:    
  - platform: "mqtt"
    name: "PWR_OUTLET_2_state"
    state_topic: "zigbee/0x842e14fffeaaaaaa" ### PWR_OUTLET_2
    value_template: "{%if is_state(switch.pwr_outlet_2,\"On\")-%}On{%-else-%}Off{%-endif%}"

You have the wrong state. It is lower case on. You can check this in Developer Tools / States

Open your Home Assistant instance and show your state developer tools.

template:
  - binary_sensor:
      - name: "PWR_OUTLET_2 State"
        state: "{{ is_state('switch.pwr_outlet_2', 'on') }}"
        device_class: power

The device class gives a nice icon set, see: https://www.home-assistant.io/integrations/binary_sensor/#device-class you can omit this if you wish.