Converting psuedo code logic to a script in HASS

i want to translate the following code to be run in a HASS script but i have no idea how to start with this:

currentIndex = last value published by topic /home/tempsensor
mode = input_select.ac1_auto_mode
minIndex = input_number.ac1_auto_min_index
maxIndex =  input_number.ac1_auto_max_index

if (mode == "Cool")
{
	if (currentIndex > minIndex) 
	{
		run remote.send_command -> { "entity_id":"remote.ac_1", "command":"cold" }
	}
}
else if (mode == "Warm")
{
	if (currentIndex < maxIndex) 
	{
		run remote.send_command -> { "entity_id":"remote.ac_1", "command":"warm" }
	}
}

any help would be appreciated

Unfortunately, this is not easily done in a single script.

You’ll need an MQTT Sensor to get the last value of /home/tempsensor

And since scripts can’t do “else if” or “else”, you’ll need one script to start it off, and additional scripts with conditions to achieve these goals.

A far easier way to accomplish this is with a python_script or with AppDaemon. For either of those, you’ll need to learn a little python. NodeRed is another popular option (that I don’t care for myself). So you may want to look into that as well.

1 Like

i’m on it - thx. going with the python approach.

just a small related question - trying to use:

sourceSensor = hass.states.get('input_select.ac1_auto_source_sensor')
logger.info('sourceSensor=%s', sourceSensor)

in a python script, but the output is not the state:

sourceSensor=<state input_select.ac1_auto_source_sensor=Sensor 1; options=['Sensor 1'], friendly_name=AC1 Source Sensor @ 2019-08-06T22:30:02.057967+03:00>

how do i get the selected field’s text from the input select?

I would assume sourceSensor is a state object, so try sourceSensor.state.

2 Likes

working - thx :slight_smile:

1 Like