template:
- sensor:
- name: "josh_thermostat_power"
unit_of_measurement: W
device_class: energy
value_template: "{{ state.attr('switch.sonoff_10013bf60d', 'power')"
It is exactly what it says.Trying to create a template sensor for a power attribute on a sonoff pow. Currently using the entity card to see the power attribute but would like it as its own sensor in orer to use as an energy sensor via the Riemann sum helper (just found out about this helper and its a life changer). however cant get my template to work, get no errors when checking the config but an error after restarting shows the following under the log:
Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected end of template, expected 'end of print statement'.) for dictionary value @ data['sensor'][0]['state']. Got "{{ state.attr('switch.sonoff_10013bf60d', 'power')". (See /config/configuration.yaml, line 43).
config.yaml is as follows- tried with and without unit of measuremeant and no changes, sensor wont show up
YAML:template: - sensor: - name: "josh_thermostat_power" unit_of_measurement: W device_class: energy value_template: "{{ state.attr('switch.sonoff_10013bf60d', 'power')"
thanks, that did the trick and sensor was picked up, but doesnt show any data and state is unavialableIt is exactly what it says.
Template value start with {{ and end without the closing of them. Eg. You need to add them. At the end.
template:
- sensor:
- name: "josh_thermostat_power"
unit_of_measurement: W
device_class: energy
value_template: "{{ state.attr('switch.sonoff_10013bf60d', 'power') }}"
copy/paste the template value into the developer tools in the template tab to test it.thanks, that did the trick and sensor was picked up, but doesnt show any data and state is unavialable
YAML:template: - sensor: - name: "josh_thermostat_power" unit_of_measurement: W device_class: energy value_template: "{{ state.attr('switch.sonoff_10013bf60d', 'power') }}"
i get the error "UndefinedError: 'state' is undefined"copy/paste the template value into the developer tools in the template tab to test it.
i get the error "UndefinedError: 'state' is undefined"
Your use of state attribute in the template is incorrect, it should be:i get the error "UndefinedError: 'state' is undefined"
value_template: "{{ state_attr('switch.sonoff_10013bf60d', 'power') }}"
How so, i compared your suggested config to mine and looks the same?Your use of state attribute in the template is incorrect, it should be:YAML:value_template: "{{ state_attr('switch.sonoff_10013bf60d', 'power') }}"
Mine looks like this:made some progress, in the template editor i get a value finally with this output.
template:
- sensor:
- name: "josh_thermostat_power"
unit_of_measurement: "W"
value_template: "0.0"
However entity still shows as unavailable and error as folows on the logs:
Invalid config for [template]: [value_template] is an invalid option for [template]. Check: template->sensor->0->value_template. (See /config/configuration.yaml, line 43).
Hvae read something around entities that show 0 values but not sure how to resolve them.
sensor:
- platform: template
sensors:
pool_power:
friendly_name: 'Pool Power'
unit_of_measurement: 'W'
value_template: "{{ state_attr('switch.sonoff_1000f4xxxx', 'power') }}"
thanks, tried to replicate it and changing the details but get a whole bunch of errors now, could also be indentationMine looks like this:
Code:sensor: - platform: template sensors: pool_power: friendly_name: 'Pool Power' unit_of_measurement: 'W' value_template: "{{ state_attr('switch.sonoff_1000f4xxxx', 'power') }}"
Then use the utility meter to sum this per day or month.
Weird. Works like that for me.thanks, tried to replicate it and changing the details but get a whole bunch of errors now, could also be indentation
Invalid config for [sensor.template]: expected dictionary for dictionary value @ data['sensors']. Got None extra keys not allowed @ data['josh_thermostat_power']. Got None extra keys not allowed @ data['unit_of_measurement']. Got 'W' extra keys not allowed @ data['value_template']. Got "{{ state_attr('switch.sonoff_10013bfxxxd', 'power') }}". (See ?, line ?).
Yours had a period (state.attr) instead of an underscore (state_attr).How so, i compared your suggested config to mine and looks the same?
Ive had it happen on a test bench when not "keeping up" with updates.My home assistant is on version 2022.2.1 and latest is 2022.4.7. However the update doesn't work, it starts but then just goes back to the update screen with no errors shown or in the log. Anyone else have issues with this update?
62GB! Hectic.FWIW, I updated my 2022.4.6 to 2022.4.7 and then Mosquito Broker 6.0.2 and Samba and everything (especially PAI (alarm integration for those that don't know) is still working.
Decided to do it, as my PC had just completed a backup of the HASS VM and I thought best time to try without doing backups inside HASS.
Microsoft and my ISP must hate me. I backup the VM to OneDrive and then my second PC downloads it (via OneDrive too). Creates a 62GB load on ISP line every 2 days!
Run version="stable"
ghcr.io/home-assistant/home-assistant:stable
Run matcher="/home/runner/work/_actions/frenck/action-home-assistant/v1.3/matcher.json"
Run docker run --rm \
2022.4.7
Testing configuration at /github/workspace/.
INFO:homeassistant.util.package:Attempting install of msmart==0.2.2
Run version="beta"
ghcr.io/home-assistant/home-assistant:beta
Run matcher="/home/runner/work/_actions/frenck/action-home-assistant/v1.3/matcher.json"
Run docker run --rm \
2022.5.0b3
Testing configuration at /github/workspace/.
INFO:homeassistant.util.package:Attempting install of msmart==0.2.2
Run version="dev"
ghcr.io/home-assistant/home-assistant:dev
Run matcher="/home/runner/work/_actions/frenck/action-home-assistant/v1.3/matcher.json"
Run docker run --rm \
2022.6.0.dev20220430
Testing configuration at /github/workspace/.
INFO:homeassistant.util.package:Attempting install of msmart==0.2.2
FWIW, I updated my 2022.4.6 to 2022.4.7 and then Mosquito Broker 6.0.2 and Samba and everything (especially PAI (alarm integration for those that don't know) is still working.