I thought I would bit the bullet and ask my first question here… This community has been amazing, and going through other posts I’ve managed to solve most things and learn quite a bit (only a couple months in with HA and don’t know why I didn’t do this sooner!).
Hopefully this is an easy one (again, I’m still sort of feeling my way around):
I made a couple IR blasters from a couple ESP boards and transmitters (receivers to get the codes from the remotes). Followed a couple guides and official doc for the YAML for ESPHome using those sensors. They work great! But…
Since each entity for the remotes I did this for are “buttons”, there is no on/off state. I wanted to be able to have the Lovelace button in my dashboards indicate whether they are on or off (like my lights), and be able to use the state in a couple automations. This isn’t possible as things are…
An example of one device I am using, the YAML for a fan has this:
button:
- platform: template
name: "Fan Power"
on_press:
- remote_transmitter.transmit_pronto:
data: "0000 006D 0048..."
- platform: template
name: "Fan Speed"
on_press:
- remote_transmitter.transmit_pronto:
data: "0000 006D 0060..."
I have a Kasa smart plug on the devices that I thought I could use the power consumption entity to provide the state of the devices, which playing in the template section of the developer tools, this seems to give me what I’m after (shows “on” or “off” depending on the current):
{% if states('sensor.fan_smart_plug_current_consumption', 'W') | float > 10 %}
On
{%- else -%}
Off
{%- endif %}
Problem is, I’m not sure how to tie it all together…
I don’t know if I should be changing this (in the YAML for the ESPHome device) for the power button to:
switch:
- platform: template
name: "Fan Power"
turn_on_action:
- remote_transmitter.transmit_pronto:
data: "0000 006D 0048..."
...
button:
- platform: template
name: "Fan Speed"
on_press:
- remote_transmitter.transmit_pronto:
data: "0000 006D 0060..."
(Still getting the hang of the YAML, sorry!) But, basically changing the button entity of the power to a switch and adding some lines for the state conditional to the code I mentioned above?
Or, I’ve read a bit about putting a binary_sensor snippet into the configuration.yaml for this, but I’m just not 100% sure how/where my code would go - for example, I saw something like this:
binary_sensor:
- platform: template
sensors:
esp_mstrbdrm_ir:
friendly_name: "Fan Power Status"
device_class: power
icon_template: mdi:power
value_template: >-
{% if states('sensor.fan_smart_plug_current_consumption', 'W') | float > 10 %}
on
{%- else -%}
off
{%- endif %}
(I’ve tried this and reloaded my config, but see no new entity showing up)
But would this not just create a new entity on the device that just provides the state? I guess I’m just confused with how I might be able to tie it all together so I can simply add the button to the dashboards with some indication that the device is on/off based on the current_consumption sensor, and when pressed controls the device.
I’ve seen reference to using scenes, script as well, just not sure the best approach that will do what I’m trying to accomplish. Perhaps creating a switch in the configuration.yaml using value_template for the states and a script to trigger the button press - then add that as a dashboard button? (my mind going in too many directions, and looking for some direction, lol)
I think it’s easy enough to use just a ‘state’ to control the device with automations - so I’m less concerned about that.
I’m very sorry if I’m doing a shoddy job at explaining myself, but any help/direction anyone can provide would be extremely appreciated (I’ve been at this for hours)!