Yep, did that already.
The four sensors per plug used to have 72 lines; thanks to the anchors I’m down to 30.
I’ll be content with this; that package is working now and will possibly grow very old before I feel the need to tamper with it again.
You also don’t need to do that at all and you can define them in place.
mqtt:
sensor:
- unique_id: zp_import
state_topic: '70:B3:31:F2/energy-solar-sdm630-modbus/f339a2fb/import'
<<: &energy
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- unique_id: zp_import_2
state_topic: '70:B3:31:F2/energy-solar-sdm630-modbus/f339a2fb/import2'
<<: *energy
Sure had that before .
But after adding and deleting several sensors I got tired of having to move those anchors also, I decided to create them atop and never need to think of them afterwards . Just inject wherever.
We don’t need to, but we can. It’s just a matter of what s most convenient
Ok, got it working for the battery part.
But the sensors also report temp and humidity. To calibrate them I’d like to add a slider. Is it possible to use anchors with an input_number? I’d like to avoid making 20 nearly identical input_numbers.
Can you help me make one input_number, just like we’ve done with the battery template sensor? Tried searching, but found nothing useful. Should there be docs or topics similar to this, then a link is also welcome.
Afaik input_numbers don’t have unique_id’s (or something alike)
input_number:
temp_corr:
name: Temp correction 001
unit_of_measurement: "°C"
min: -10
max: 10
step: 0.1
icon: mdi:pencil-outline
mode: slider
Well just put everything you want to be the same under the <<: & define anchor and paste that with the <<: *
Just like the post above does. Remember, this is a yaml thing not Ha. So as long as the yaml is valid you’re good to go. Backend/frontend no matter where
Tried it, but must be doing something wrong.
Configuration invalid!
Error loading /config/configuration.yaml: while constructing a mapping in
"/config/configuration.yaml", line 49, column 5 expected a mapping or
list of mappings for merging, but found scalar in "/config/configuration.yaml",
line 50, column 9
Is <<: &tag_temp_corr placed wrongly?
Got it working. Apparently Yaml expects the anchor code to be indented:
input_number:
tag_0001_temp_corr:
name: "Temperatuur correctie 1"
<<: &tag_temp_corr
unit_of_measurement: "°C"
min: -10
max: 10
step: 0.1
icon: mdi:pencil-outline
mode: slider
it only expects the anchor to be indented when you’re declaring it in a place that doesn’t have a dedicated field to put the anchor on.
e.g. normal indentation
some_field: &new_anchor
stuff_in_anchor_1: value1
stuff_in_anchor_2: value2
stuff_in_anchor_3: value3
vs (some_field isn’t valid in this case)
<<: &new_anchor
stuff_in_anchor_1: value1
stuff_in_anchor_2: value2
stuff_in_anchor_3: value3
I played with indentation and it only accepted it as in my example code. It works, thats what matters
Yes, I’m explaining to you why it only works that way