The UPS sends values like “180 Watt(40 %)” to an mqtt topic “daemon/ups/loads”. I want to use a value_template
(doc) to parse out the first word, “180”, for an MQTT sensor (doc). This is what I’ve tried:
config.yaml:
mqtt:
sensor:
- name: "Bedroom UPS Load"
unique_id: "bedroom_ups_load"
state_topic: "daemon/ups/loads"
value_template: "{{value.split(' ')[0]}}"
unit_of_measurement: "W"
device:
name: "Bedroom UPS"
identifiers: ["CP800AVRa"]
manufacturer: "CyberPower"
model: "CP800AVRa"
But in homeassistant, this gives a value of Unknown
. I have also tried setting value_template
to:
{{value.split()[0]}}
{{value.split[0]}}
{{value|split[0]}}
{% set words = value.split %}{{words[0]}}
But none of these work.