I’ve recently gotten a sonoff pow v2 working with sonoff-tasmota flashed to it.
configuring the mqtt switch and mqtt sensor entities in configuration.yaml and getting them integrated into the frontend was easy enough, but i can’t find a way to assign the sensor data as attributes of the switch itself.
i would like to be able to see the power attributes in the more info dialog that comes up when you click the switch title. the etekcity voltson (using vesync) does this by default:
i’ve seen a few threads that say using appDaemon is a way to achieve this, but what i’m attempting seems so simple that i would think there would be a way to accomplish it in yaml that i’m just unaware of. i’ve also looked at template switches and mqtt switches but don’t see any obvious avenues to adding attributes to them in their configuration.
alternatively, i’ve considered trying to modify the tasmota mqtt code flashed to the device via the arduino ide, in hopes that maybe i could structure the topics in such a way that hassio would automatically associate them together and merge the sensor data and switch into one entity. however, as far as i can tell, there isn’t any implementation in hassio to perform this.
is there a simple solution to adding the power usage telemetry to a switch as attributes in hassio?
…or at least a well-documented complex solution?
thanks, but my issue isn’t how to implement the sensor into hass itself. in fact, i’m using that exact code that you provided. what i’m trying to do is find a way to assign the output values of those sensors to the sonoff switch entity as attributes, as shown in my screenshot above.
If I test this I receive error in check config because command_topic is required (!)
Invalid config for [switch.mqtt]: required key not provided @ data[‘command_topic’]. Got None. (See ?, line ?). Please check the docs at MQTT - Home Assistant
The strange thing is that looking at the docs the topic should be not mandatory:
command_topic
(string)(Optional)
The MQTT topic to publish commands to change the switch state.
I want to create as topic a switch for a sonoff pow r2 that has energy as attributes in order to allow an automation to switch off only if the value are above a certain power.
I don’t understand when you ask about pairing or platform. My sonoff pow is running tasmota 7.1 at the moment.
If you are wondering why I do not simply use info from the sensor the answer is that this macro control all device in a input list and if the overall power consumption of my apartment is above a value it starts to switch off one by one devices in that list. That’s why I think I need that those info are inside the swich, so I can add a condition in it:
- service: homeassistant.turn_off
data_template:
entity_id: >-
{%- macro dss_spegni_primo_carico() -%}
{%- set entity_carico_da_spegnere = states.input_select.lista_carichi.attributes.options|join(',')-%}
{%- for item in entity_carico_da_spegnere.split(',') if (states(item) != 'off' and (item != ''))-%}
{{ item }}{% if not loop.last %},{% endif %}
{%- endfor -%}
{%- endmacro -%}
{{ dss_spegni_primo_carico().split(',') | first }}
try this (it can be optimized but i’m splitting it up so you understand better
{% set attribute = 'power' %}
{% set value = 5 %}
{% set entities = states | selectattr('entity_id','in', states.input_select.lista_carichi.attributes.options) | list %}
{% set on_entities = entities | selectattr('state','eq','on') | list %}
{% set on_and_above_value = on_entities | selectattr('attributes.%s'%attribute, '>', value) | list %}
{{ on_and_above_value | first }}