MQTT action & expressions
-
I have a case where I'm trying to send a MQTT message similar to the example below:
Topic: pool/set { "command": 4, "value": 1, "time": 0, "interval": 0 }
But I need to set "value" so that it is an integer between 20-30. I thought I could use "dimming" capability here, but there's probably a better way. @therealdb ?
-
I have a case where I'm trying to send a MQTT message similar to the example below:
Topic: pool/set { "command": 4, "value": 1, "time": 0, "interval": 0 }
But I need to set "value" so that it is an integer between 20-30. I thought I could use "dimming" capability here, but there's probably a better way. @therealdb ?
@tunnus yep, dimming is probably fine, but if you're sending a temperature, I'll go with hvac_heating_unit.set_setpoint.
I truly love the ability to map things to "virtual devices", it's so refreshing when compared to the old vera way and I built a custom dashboard that's mapping things directly from MSR APIs and reusing standard capabilities is my favorite thing.
-
@tunnus yep, dimming is probably fine, but if you're sending a temperature, I'll go with hvac_heating_unit.set_setpoint.
I truly love the ability to map things to "virtual devices", it's so refreshing when compared to the old vera way and I built a custom dashboard that's mapping things directly from MSR APIs and reusing standard capabilities is my favorite thing.
@therealdb so something like below?
template:
pool_set_temp: type: hvac_heating_unit ??? capabilities: ["hvac_heating"] primary_attribute: hvac_heating_unit.setpoint ??? actions: hvac_heating: set_setpoint: topic: "pool/set" payload: type: json expr: "{ 'command': 4, 'value': set_setpoint, 'time': 0, 'interval': 0 }"
Also, there would need to be a check for value range of 20-30, so adding that, maybe something like below could work?
expr: "{ 'command': 4, 'value': min( 30, max( 20, int( set_setpoint ) ) ), 'time': 0, 'interval': 0 }"
-
@tunnus Small correction to the capability name in the array:
capabilities: [ hvac_heating_unit ]
Also, you don't need the single quotes in the expression, because none of the key names in the object contains any special characters.
The
type
would not apply with this entity, because I have no yet provided widget that works with HVAC capabilities in the dashboard (type
is a dashboard hint).Edit: I whipped up superficial support for
hvac_heating/cooling_unit
in the Dashboard, in build 24137. It will get embellishments later. -
@therealdb so something like below?
template:
pool_set_temp: type: hvac_heating_unit ??? capabilities: ["hvac_heating"] primary_attribute: hvac_heating_unit.setpoint ??? actions: hvac_heating: set_setpoint: topic: "pool/set" payload: type: json expr: "{ 'command': 4, 'value': set_setpoint, 'time': 0, 'interval': 0 }"
Also, there would need to be a check for value range of 20-30, so adding that, maybe something like below could work?
expr: "{ 'command': 4, 'value': min( 30, max( 20, int( set_setpoint ) ) ), 'time': 0, 'interval': 0 }"
@tunnus almost there. expression should get the value from
setpoint
attribute viaparameters
.so:
pool_set_temp: type: hvac_heating_unit capabilities: [hvac_heating] primary_attribute: hvac_heating_unit.setpoint actions: hvac_heating: set_setpoint: topic: "pool/set" payload: type: json expr: { 'command': 4, 'value': min( 30, max( 20, int( parameters.setpoint ) ) ), 'time': 0, 'interval': 0 }
EDIT: I don't know if you're controlling this device only via MQTT and/or you want to update its status via MQTT, but in this case look at events. Best example from https://github.com/dbochicchio/reactor-mqtt-contrib is imho shelly_relay_power.yaml
-
@tunnus almost there. expression should get the value from
setpoint
attribute viaparameters
.so:
pool_set_temp: type: hvac_heating_unit capabilities: [hvac_heating] primary_attribute: hvac_heating_unit.setpoint actions: hvac_heating: set_setpoint: topic: "pool/set" payload: type: json expr: { 'command': 4, 'value': min( 30, max( 20, int( parameters.setpoint ) ) ), 'time': 0, 'interval': 0 }
EDIT: I don't know if you're controlling this device only via MQTT and/or you want to update its status via MQTT, but in this case look at events. Best example from https://github.com/dbochicchio/reactor-mqtt-contrib is imho shelly_relay_power.yaml
@therealdb & @toggledbits it wasn't that easy... I finally got this working, but it took a couple of iterations. Correct version below:
pool_set_temp: capabilities: [ hvac_heating_unit ] primary_attribute: hvac_heating_unit.setpoint actions: hvac_heating_unit: set_setpoint: topic: "pool/set" payload: type: json expr: '{ "command": 4, "value": min( 30, max( 20, int( parameters.setpoint ) ) ), "time": 0, "interval": 0 }'
Devil is in the details I guess.
-
T tunnus marked this topic as a question on
-
T tunnus has marked this topic as solved on
-
T toggledbits locked this topic on