I have a trigger wire from the headunit in my boat that switches internal relays in the amps and subs when the headunit is turned on (like most headunits with aux and sub out has). A script in the ESP needs to know if that is live or not (to send an IR on signal if turning on the relay to it isn’t enough). Since there is a bit of “leakage” I need to set it to 10V, so an if → then in the script has that as a condition. But i’m not sure how to do it. This is the sensor:
Thank you for answering! RTFM. But IDRTFMADUS… I did RTFM and didn’t understand sh|t. I’m pretty good with LUA. I’m OK at Python. I’m hopeless in YAML. Couldn’t code myself out of a brown paper bag. I stitch together code from here and there and try to make it as simple as possible. Only this one I couldn’t find aywhere, and as I said I didn’t understand the manual. Does that mean that there’s no easy way to do this?
You probably should also read Sensor Automation under Sensor Core:
This one will trigger EVERY sensor update if the value is above 10:
sensor:
- platform: ina219
id: my_sensor
i2c_id: bus_a
address: 0x40
shunt_resistance: 0.1 ohm
bus_voltage:
name: "Anlegg"
max_voltage: 32.0V
max_current: 3.2A
update_interval: 5s
on_value:
if:
condition:
sensor.in_range:
id: my_sensor
above: 10.0
then:
# something here that does what you want, i.e a script or control an output
- script.execute: my_script
This one will trigger ONCE when the sensor passes the value 10:
sensor:
- platform: ina219
id: my_sensor
i2c_id: bus_a
address: 0x40
shunt_resistance: 0.1 ohm
bus_voltage:
name: "Anlegg"
max_voltage: 32.0V
max_current: 3.2A
update_interval: 5s
on_value_range:
- above: 10.0
then:
# something here that does what you want, i.e a script or control an output
- switch.turn_on: relay_3
There are plenty of other options, with the examples in the two linked pages you should be able to figure it out.
Took time to get back again, I’ve been drowning in work for a month. But today I got back to this, and I found that the solutions were misunderstood. I only wanted to use the voltage as a condition, not a trigger. But this code works:
- topic: madmax/anlegg/på
then:
- if:
condition:
switch.is_on: styrehusrele1
then:
- mqtt.publish:
topic: madmax/stereoanlegg
payload: "Styrehusrelé 1 er allerede på - sjekker om styrestrøm er på"
- if:
condition:
lambda: |-
return id(Styrestrom_anlegg).state > 5.0;
then:
- mqtt.publish:
topic: madmax/stereoanlegg
payload: "Styrestrømmen er på IR er unødvendig"
else:
- mqtt.publish:
topic: madmax/stereoanlegg
payload: "Slår på anlegg med IR"
- remote_transmitter.transmit_pioneer:
rc_code_1: 0xB50A
else:
- mqtt.publish:
topic: madmax/stereoanlegg
payload: "Styrehusrelé 1 er av, slår på nå - og venter for å sjekke om IR trengs"
- switch.turn_on: styrehusrele1
- delay: 4s
- if:
condition:
lambda: |-
return id(Styrestrom_anlegg).state > 5.0;
then:
- mqtt.publish:
topic: madmax/stereoanlegg
payload: "Styrestrømmen er på IR er unødvendig"
else:
- mqtt.publish:
topic: madmax/stereoanlegg
payload: "Slår på anlegg med IR"
- remote_transmitter.transmit_pioneer:
rc_code_1: 0xB50A